Prevent Next Handler / Callback Calling

I have a global error handler for AJAX errors:

$(document).ready(function() {
    $(document).ajaxError(ajaxErrorHandler);
});

function ajaxErrorHandler(event, jqxhr, settings, exception) {

    // ...

    // How to stop further processing of the AJAX response here?
}

Once I processed the error, I do not want the AJAX response to be processed further. How to stop a callback complete? (My AJAX requests are created inside the library, and I cannot determine their parameters).

UPDATE:

The call jqxdr.abort()does not complete the job.

+4
source share
2 answers

You can try this in your handler:

function ajaxErrorHandler(event, jqxhr, settings, exception) {

    // ...

    // How to stop further processing of the AJAX response here?
    event.stopPropagation();
}

It will stop the event passing to the parent handlers.

+2
source

Here is the complete list of ajax events triggered: jQuery doc

complete ajaxComplete ( ). , ajaxErrorHandler, , complete .

complete success error, evt.stopPropagation() evt.stopImmediatePropagation() .


jQuery, succes/failure, .

, ( resolved / rejected, completed), .

: ajaxError complete ajaxComplete.

+1

Source: https://habr.com/ru/post/1529116/


All Articles