[removed] How to stop multiple jQuery ajax error handlers?

前端 未结 2 1812
甜味超标
甜味超标 2021-01-04 09:55

A team member put this into our project

$(function() {
    $(\"body\").bind(\"ajaxError\", function(event, XMLHttpRequest, ajaxOptions, thrownError){
                


        
2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-04 10:34

    I would just throw a boolean into your code that's defaulted to false. Set it to true the first time the error is thrown and make sure to check for true at the start of the error function.

    Something like:

    function blah() {
        var errorHappened = false;
    
        ...
    
        errFunc = function(event, xhr, opts, errThrown) {
            if (errorHappened)
                return;
    
             errorHappened = true;
    
             // handle the errror.
    
        }
    
        // the rest of your code
    
    }
    

提交回复
热议问题