jQuery $.ajaxError() runs on 200 - OK

ajax, jquery

Solution

ah, well after days of searching i commented out different settings in $.ajaxSetup(). It ended up being that i had set a timeout. If only there was a better error message given. Thanks for all the help guys, would not have gotten here if not for you. You all get up votes!!!

Problem

I have a global ajax error handler that runs even though the xhr.status is 200, xhr.statusText is "OK" and xhr.responseText is my JSON string. This happens in firefox and IE. ``` $.ajax({ data: { method: "getRequestDetails", loggedInUsername: loggedInUsername, search: search }, success: function(data){ var arrayObject = eval("(" + data + ")")['DATA']; if (arrayObject.length == 0){ alert("That search term returned no results"); } else { callBeforeShow("Results"); $.each(arrayObject, function(index, value){ showJSON(value, "Results"); }); callAfterShow("Results"); } } }); $(document).ajaxError(function(event, XMLHttpRequest, ajaxOptions, thrownError){ var errorMessage = "Ajax Error\n"; errorMessage += "Type: " + ajaxOptions.type + "\n"; errorMessage += "Requesting Page: " + ajaxOptions.url + "\n"; errorMessage += "Status: " + XMLHttpRequest.status + " - " + XMLHttpRequest.statusText + "\n"; errorMessage += "Error Thrown: " + thrownError alert(errorMessage); }); ``` In IE this says that the XMLHttpRequest is not ready and in Firefox this returns "AJAX Error" "Type: POST" "Requesting Page: something.CFC" "Status: 200 - OK" "Error Thrown: undefined" So my work around is to use ``` $(document).ajaxComplete(function(event, XMLHttpRequest, ajaxOptions, errorThrown){ if (XMLHttpRequest.status != 200){ var errorMessage = "Ajax Error\n"; errorMessage += "Type: " + ajaxOptions.type + "\n"; errorMessage += "Requesting Page: " + ajaxOptions.url + "\n"; errorMessage += "Status: " + XMLHttpRequest.status + " - " + XMLHttpRequest.statusText; alert(errorMessage); } }); ``` EDIT *This only happens on some occassions. Most of the time it works but sometimes it runs $.ajaxError()* EIDT ``` {"COLUMNS":["ID","SUMMARY_SPEC","TOTAL_EFFORT","EFFORT_HISTORY","LOG_HISTORY"],"DATA":[[816,"test only","2 Minutes - Last Updated: 09\/12\/2010",{"COLUMNS":["CC_ID","RECORD_ID","USER_ID","USER_NAME","EFFORT_DATE","EFFORT_DAYS","EFFORT_HRS","EFFORT_MINS","EFFORT_TOT_HRS"],"DATA":[[816,496,"ruhlet","Tim Ruhle","December, 09 2010 00:00:00",0,0,1,0.0167],[816,497,"ruhlet","Tim Ruhle","December, 08 2010 00:00:00",0,0,1,0.0167]]},{"COLUMNS":["CC_ID","RECORD_ID","USER_ID","USER_NAME","LOG_DT","LOG_ENTRY"],"DATA":[]}]]}{"COLUMNS":["ID","SUMMARY_SPEC","TOTAL_EFFORT","EFFORT_HISTORY","LOG_HISTORY"],"DATA":[[816,"test only","2 Minutes - Last Updated: 09\/12\/2010",{"COLUMNS":["CC_ID","RECORD_ID","USER_ID","USER_NAME","EFFORT_DATE","EFFORT_DAYS","EFFORT_HRS","EFFORT_MINS","EFFORT_TOT_HRS"],"DATA":[[816,496,"ruhlet","Tim Ruhle","December, 09 2010 00:00:00",0,0,1,0.0167],[816,497,"ruhlet","Tim Ruhle","December, 08 2010 00:00:00",0,0,1,0.0167]]},{"COLUMNS":["CC_ID","RECORD_ID","USER_ID","USER_NAME","LOG_DT","LOG_ENTRY"],"DATA":[]}]]}{"COLUMNS":["ID","SUMMARY_SPEC","TOTAL_EFFORT","EFFORT_HISTORY","LOG_HISTORY"],"DATA":[[816,"test only","2 Minutes - Last Updated: 09\/12\/2010",{"COLUMNS":["CC_ID","RECORD_ID","USER_ID","USER_NAME","EFFORT_DATE","EFFORT_DAYS","EFFORT_HRS","EFFORT_MINS","EFFORT_TOT_HRS"],"DATA":[[816,496,"ruhlet","Tim Ruhle","December, 09 2010 00:00:00",0,0,1,0.0167],[816,497,"ruhlet","Tim Ruhle","December, 08 2010 00:00:00",0,0,1,0.0167]]},{"COLUMNS":["CC_ID","RECORD_ID","USER_ID","USER_NAME","LOG_DT","LOG_ENTRY"],"DATA":[]}]]} ``` The latest version of firebug recognises it as json.

Original source