Reputation: 380
I have a page with a lot of jquery requests. I always add something like this to my calls...
error: function(xhr, ajaxOptions, thrownError)
{
alert('Error in AJAX response. Please see console log for details.');
console.log(thrownError);
console.log("readyState: " + xhr.readyState);
console.log("responseText: "+ xhr.responseText);
console.log("status: " + xhr.status);
}
Question: Is there a simpler less repetitive way to do this? Rather than adding it to each request.
Upvotes: 0
Views: 31
Reputation: 349946
Check out $.ajaxSetup()
. You can do something like this once, and it will apply to all subsequent ajax calls you make via jQuery:
$.ajaxSetup({
error: function () {
alert('error');
}
});
Upvotes: 2