Global AJAX method

Using following two ways you can handle all AJAX errors of your application at one central place.

Include these files in a common JS file which is available across all pages.

  1. ajaxSetup

$(function() {

error : function(jqxhr, status, error) {
//do some action

2.  ajaxError

$(document).ajaxError(function(event, jqxhr, settings, thrownError) {
//do some action


Difference between ajaxSetup and ajaxError:

Well both can catch AJAX errors but in case of ajaxSetup, it would not be invoked if error method is defined individually for AJAX call, it would catch the errors only when error method is not defined for any AJAX call.

Whereas ajaxError always catches ajax error even if error method is defined for individual AJAX call.


So for examle, AJAX call has its own individual error method.

In case of ajaxSetup: error method of ajax call would be executed, ajaxSetup would not be executed.

In case of ajaxError: error method of ajax call would be executed, ajaxError would also be executed.