Mail/Login: Password : forgot my password!

IE6, IE7, AJAX and the uninitialized .readyState

Direct link
Written by -GHAN- // Tags: ajax readystate ie6 ie7

That damn thing! ... IE is such a bastard. After having optimized my xhr core to reuse the object, IE6 and IE7 decided only to do the initial request and after that skip further actions. I took a deeper investigation on that.

How did I get there!?

Currently working on a new look-up widget I decided to place some new features in the way requests are done. I remember the first request code to be lame and causing to define an ajax request everytime you need a request. This is definitely not the way to do this!
So, if you plan to do a Ajax core (e.g. a function doing the definitions and returning an object which makes life pretty easy) your considerations should include the reuse of already existing objects. As I'm fine with that, I did so and checked if the former aqquired xhr object is there, and if not then just go create one:
Sorry- ... please log-in or register to get this!

So ... sanity checks in shape as we head on and everything worked out as planed. Next I needed to define a state handler for the xhr in order to handle the request in the right manner. In my case this is a function within:

Sorry- ... please log-in or register to get this!

Sorry- ... please log-in or register to get this!
A xhr.readyState at 4 lets you know: "Request has finished". And here comes the trouble.
After having done the first request, in IE6 the xhr.readyState stays 4! ... every other browser initializes this readyState as a new request starts. But not IE6! Even worse is the point, that you can't change that value by hand as it is read-only :) That's far down the drain and needs a whip as well as a workaround.

Fixing the readyState

As we have no other option but to initialize the state to a fitting value for IE, the workaround is as plain as well as stupid. We check it before we start the next request:

Sorry- ... please log-in or register to get this!

Final notes

It seems to be a good idea to build a check for IE6 in order not to get a new object everytime a request is launched. For IE6 and IE7 and only for those this is the tweak. Needless to mention, never browsers handle this in a smarter and correct way.


894 view(s) / 2010-02-23 19:13:09 / LAST UPDATED: 2011-07-13 16:07:12