views:

35

answers:

3

I have many places in my code doing "$.ajax" call can I define one place to handle all errors ?

I know there is "error: function ... " that I can place in each call , but I want to write it just one time

A: 
$.ajaxSetup({});
czarchaic
How very...terse. @OP: It sets default options for Ajax requests. Link: http://docs.jquery.com/Ajax/jQuery.ajaxSetup#options
T.J. Crowder
do you have a sample code ?
haddar
$.ajaxSetup({ error: function(XMLHttpRequest, textStatus, errorThrown) { alert(XMLHttpRequest + ':' + textStatus + ':' + errorThrown); return false; } });is this OK ?
haddar
@haddar: There's sample code in the docs I linked (click the "Examples" tab). But that looks about right, yeah.
T.J. Crowder
+2  A: 

How 'bout the ajaxError event?

T.J. Crowder
A: 

You can define your error handling function just once and then refer to it in the Ajax call rather than using function literals in each call.

Rich