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) {

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) {

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.

About gopha

Gopha is a web programmer, techie and heir to several Nigerian fortunes. In his spare time he likes to game, spend time with his wife, daughters and dogs. He eats [far too much], watches TV and lift weights. He also like to take moonlit walks on the beach and sing songs next to a roaring campfire, in a white sweater with his acoustic guitar. View all posts by gopha

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: