Generic Error Message in an Ajax call using jQuery

The jquery $.ajaxSetup() allows you to set default values for future Ajax requests. Here’s how to use this function to set a default generic error message

$.ajaxSetup({
error: function(e, xhr, options, ex) {
alert("A Generic AJAX error " + ex);
}
});

So now each time an error occurs during an ajax request and the error is not handled, this error message will be used automatically.

Note: jQuery uses $.ajaxerror to register a handler to be called when Ajax requests complete with an error






About The Author

Suprotim Agarwal
Suprotim Agarwal, Developer Technologies MVP (Microsoft Most Valuable Professional) is the founder and contributor for DevCurry, DotNetCurry and SQLServerCurry. He is the Chief Editor of a Developer Magazine called DNC Magazine. He has also authored two Books - 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook.

Follow him on twitter @suprotimagarwal.

No comments: