Prevent .ajaxError for calling if handled elsewhere

I have a global $(document).ajaxError that takes care of most errors for me if an unexpected 500 error occurs or something else. However, there are times when I want to catch errors locally in a script and then prohibit calling the global error handler. Is there a way to do this, for example with 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. } }); 
+4
source share
1 answer

You need to pass the global: false parameter to $.ajax as follows:

 $.ajax({ url: '/something/', global: false, success: function() { alert('Success'); } }).error(function(response)) { if (response.status == 404) { alert('Page not found'); } }); 

Link: Ajax Events , jQuery.get

+7
source

All Articles