/ Published in: jQuery
Example of how to display HTTP error code and message on ajax response
Expand |
Embed | Plain Text
$j.ajax({url: req, type: "POST", dataType: "json", data: "image=" + image + "&lbox=" + lboxVal, success: good_response, error: error_response}); function error_response(xhr,status) { //display http error and message from xhr object alert('HTTP ' + xhr.status + ' Error Encountered: ' + xhr.statusText); }
Comments
Subscribe to comments
You need to login to post a comment.

I have been using jQuery's ajaxSetup() function to set a default error handler for my Ajax requests.
It looks something link this:
$(function() {$.ajaxSetup({error: function(jqXHR, exception) {if (jqXHR.status === 0) {alert('Not connect.\n Verify Network.');} else if (jqXHR.status == 404) {alert('Requested page not found. [404]');} else if (jqXHR.status == 500) {alert('Internal Server Error [500].');} else if (exception === 'parsererror') {alert('Requested JSON parse failed.');} else if (exception === 'timeout') {alert('Time out error.');} else if (exception === 'abort') {alert('Ajax request aborted.');} else {alert('Uncaught Error.\n' + x.responseText);}}});});Full code can be found at jQuery Ajax Error Handling Function