A team member put this into our project
$(function() {
    $("body").bind("ajaxError", function(event, XMLHttpRequest, ajaxOptions, thrownError){
        alert(thrownError);
    });
}
However I want to supress one of my errors (as it would be noise and verification isn't needed)
function blah() {
    ...
    errFunc = function(event, xhr, opts, errThrown) {
        //what could I do here?
        //event.stopImmediatePropagation()?
    }
    $.ajax({
        url        : '/unimportant_background_refresh',
        type       : 'GET',
        data       : { },
        dataType   : 'json',
        success    : updateBackgroundStuff,
        error      : errFunc,  // Suppresses error message.
    });
}
How can I stop the catch all error from happenning please? Can I just do something in the error function such as { event.StopPropogation(); } or must I work out some mechanism for having the catch all selectively ignore things please?
Maintain a variable isLoading that stores the status of the request. Only if the request is not loading (i.e., there's no AJAX request in progress), do we start a new request. Otherwise, we just ignore the new click event.
Just call xhr. abort() whether it's jquery ajax object or native XMLHTTPRequest object.
version added: 1.0.Whenever an Ajax request completes with an error, jQuery triggers the ajaxError event. Any and all handlers that have been registered with the . ajaxError() method are executed at this time. Note: This handler is not called for cross-domain script and cross-domain JSONP requests.
Many pages send AJAX requests to a server. Because this relies on the cooperation of the server and the network between the client and the server, you can expect these AJAX errors: Your JavaScript program receives an error response instead of data; Your program has to wait too long for the response.
Global events can be disabled, for a particular Ajax request, by passing in the global option, like so:
 $.ajax({
   url: "test.html",
   global: false,
   // ...
 });
Taken from: http://docs.jquery.com/Ajax_Events
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With