Tech Off Thread

3 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

IE7 and XMLHttpRequest

Back to Forum: Tech Off
  • User profile image

    I have been experimenting with AJAX in IE7.  I noticed that IE7 now supports the XMLHttpRequest object so I thought I would give it a try.  So say I take the following code (I removed all of the browser checking code in the getHTTPObject function to keep it simple)....

    var xmlHttp;

       return new XMLHttpRequest();

    function xmlHttpGet( url, handler )
       xmlHttp = getHTTPObject();
       xmlHttp.onreadystatechange = handler; "GET", url );

    function xmlHttpPost( url, sendItem )
       xmlHttp = getHTTPObject(); "POST", url );
       xmlHttp.send( sendItem );

    Running this code works fine for all of the POST calls.  Running the GET works the first time.  Every time I call it after the first, it doesn't call the server.  It seems to return some cached value from the first call.
    If I change the getHTTPObject function to this...

    function getHTTPObject()
    return new ActiveXObject("Microsoft.XMLHTTP");

    It works the way I would expect.  Is this the way it is intended to work or am I just missing something obvious? 

  • User profile image
    Sven Groot

    I'm not 100% sure, but I think if you use a more recent version of the ActiveX object, like Msxml2.XMLHTTP.4.0, it would also behave that way.

    I think it's simply obeying the cache directive on the page (which it's allowed to do with a GET). Whatever you're downloading with ajax, give a no-cache directive in the headers and it should download it every time again.

  • User profile image

    You were correct Sven.

    I added Response.CacheControl = "no-cache" to my server page and it now works like a champ.


Conversation locked

This conversation has been locked by the site admins. No new comments can be made.