I have a global $(document).ajaxError handler that takes care of most errors for me just in case there is ever an unexpected 500 error or something. However, there are times when I want to catch errors locally in a script and then prevent that global error handler from being called. Is there a way to do this such as you would with an event.stopPropagation()?
Example
$.get('/something/', function() {
alert("Stuff went well.");
}).error(function(response)) {
if (response.status == 404) {
alert('Page not found');
// Do something to stop global ajaxError from being called.
}
});
You need to pass the
global: falseparam to$.ajaxlike this:Reference: Ajax Events, jQuery.get