Feb 4 2007

AJAX and IE 7

Category: AJAX-ATLAS[email protected] @ 20:36

I was all day preparing the demo code for my next article on www.aspalliance.com under the title of Introduction to JSON. I have a dropdownlist, where a user can select an item and I will show more details on the selected item. I am using AJAX and on the server I am responding by JSON-formatted text.

In IE 7, only first time I select an item works fine, I do an AJAX request and the details are shown! The second time it fails as if the OnReadyStateChange is not being called. It works fine for FireFox!

I contacted some help mainly Christian Wenz, the author of Programming ATLAS and the expert in ATLAS, he informed me that IE has a problem in recycling the existing XMLHttpRequest object.

That is why, whenever you are using XMLHttpRequest object, make sure you initialize it inside method that is doing the request and not outside the method, I mean in a global fashion. This way you make sure it runs on IE, FF, and IE7.


var postRequest;
function GetStudents() {
       postRequest = CreateXMLHttpRequest();

CreateXMLHttpRequest would be a helper function that creates a new XMLHttpRequest if usinf FF and IE7 and uses one of the ActiveXObjects in the older vresions of IE.


Hope this helps,




Comments are closed