Jquery Ajax error handling to ignore aborted

后端 未结 9 743
栀梦
栀梦 2020-12-07 17:35

I want to have a global error handling method for ajax calls, this is what I have now:

$.ajaxSetup({
  error: function (XMLHttpRequest, textStatus, errorThro         


        
9条回答
  •  再見小時候
    2020-12-07 17:46

    I had the same issue here, and what I did as solution was to set an "aborting" var just before the call of abort(), as below:

    aborting = true;
    myAjax.abort();
    

    and only show the error on the error handler of the ajax request, if abort isn't true.

    $.ajax({
        [..]
        error: function() {
            if ( !aborting ) {
                // do some stuff..
            }
            aborting = false;
        }
    });
    

提交回复
热议问题