I want to create a global ajax error handler using the jQuery ajaxError() handler, such as this:
$(document).ajaxError(function(e, xhr, settings, exception) {
alert('error in: ' + settings.url + ' \\n'+'error:\\n' + exception);
});
source: http://api.jquery.com/ajaxError/
But I want to expand on this by having the server return a JSON object instead of just text, and then my error handler can use properties of the object to decide what to do and to make a nice error dialog. But how do I do this?
I now have the server returning a valid JSON formatted string but I am used to the jQuery function having a “data’ parameter which is automatically parsed for me, how do I do this using the ajaxError function which does not have such a ‘data’ parameter?
Try looking at the responseText of the xhr object:
xhr.responseText. You may need to parse this.