Tag Archives: AJAX

Odd XMLHTTPRequest Check Error in Internet Explorer

For the past week I have been scripting, using the XMLHTTPRequest object. I use a check to see if the object receives the correct oks from the server so it can continue executing. It’s two items wrapped into a JavaScript if() statement. I test the readyState and the status. This was the if() statement I had written:

if(getXmlHttp.status == 200 && getXmlHttp.readyState == 4) {
codeToBeExecuted;
}

The code executed correctly in all browsers I tested (FF 3.5, Chrome 3, Opera 10.10, Safari 4 for Windows) and IE 8/IE 8 as IE 7. However, IE 8/IE 8 as IE 7 threw out an “Unspecified Error at character 3” error message. I did some googling and played around with some solutions (this try/catch solution worked as well). Then, I looked at some older code I did and I saw that I had written this if() statement backwards. So, I changed the if() statement to this:

if(getXmlHttp.readyState == 4 && getXmlHttp.status == 200) {
codeToBeExecuted;
}

The error no longer appears in IE 8/IE 8 as IE 7. I don’t understand why it matters to IE which goes first but this was just a big waste of time for something so trivial.