12/16/2009
Catching errors on the jQuery's load() function
Posted by
Osvel Legon
When using the jQuery's load function there is a way to catch the errors. The callback is full of parameters from the request and the response:
$("body").load("/load.aspx", function (responseText, textStatus, XMLHttpRequest) {
if (textStatus == "error") {
alert('Error!');
// XMLHttpRequest.responseText has the error info you want.
alert(XMLHttpRequest.responseText);
}
});
The XMLHttpRequest is a full XMLHttpRequest object.
Also you can register a general error handler for all the jQuery ajax calls:
$.ajaxError(function(event, request, settings) {
alert("Oops!!");
});
« Back to Blog Main Page |