Internet Explorer 9, JScript Error c00c023f
Monday, May 23 2011 @ 02:35 PM CEST
Views: 2,652
IE 9, Ajax and Error c00c023f
After updating to Internet Explorer 9, a previously working ajax driven site of mine stopped working sporadically.
In this short article you will see how to reproduce, and how to solve the problem.
Steps to reproduce
- Create a XMLHttpRequest object
- Assign an onreadystatechanged event handler
- Execute a request
- Abort the request before the response has been handled
- You will now see that the readystatechange handler will be called, with the readystate property set to '4'. Any attempt to read the XmlHttpRequest object properties will fail.
If you're not running with a debugger the exception is silent, but can still be annoying. Especially if you're displaying a "loading animation" or anything similar while the request is being executed. The result in my case was that it seemed as the page never stopped loading
Solution
Just before you call the XmlHttpRequest.abort() method, set a flag on it, this is how I did it:
XmlHttpRequest.aborted = true;
XmlHttpRequest.abort();
In the onreadystatechanged handler, the first lines of code in my case is:
if (xmlHttpRequest.aborted==true) {
stopLoadAnimation();
return;
}
And that's all there is to it, your Ajax driven site is up and running again.
