31-08-2010

jQuery Register general ajax or getJSON error handler

It's always quite handy to register something general for handling errors occuring in your script when using Ajax in jQuery:

Somewhere in your jQuey based Ajax handling scripts register a general error handler like so:

$.ajaxSetup({
  "error":function(XMLHttpRequest, textStatus, errorThrown) {
  	alert ('an error occured - please use Firebug console to view the details ')
  	if (window.console && window.console.log){
  		 console.log(textStatus);   
  		 console.log(errorThrown);   
  		 console.log(XMLHttpRequest.responseText);   
  		 console.log(XMLHttpRequest);   
  	}
}});

Comments:

2 comments.
Your comment:

»
mi 01/09/2010, 11:07 am
that's nice
Martin 12/03/2011, 4:39 pm
It saved me a lot of time !
Thanks !

Martin

 

[x]