Posted By: JeremyJ | Jul 27th, 2006 @ 8:47 AM
page 1 of 1
Comments: 2 | Views: 5128
JeremyJ
JeremyJ
The pioneers would be appalled!
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;

function getHTTPObject()
{
   return new XMLHttpRequest();
}

function xmlHttpGet( url, handler )
{
   xmlHttp = getHTTPObject();
   xmlHttp.onreadystatechange = handler;
   xmlHttp.open( "GET", url );
   xmlHttp.send();
}

function xmlHttpPost( url, sendItem )
{
   xmlHttp = getHTTPObject();
   xmlHttp.open( "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? 

Sven Groot
Sven Groot
My name has 9 letters. Coincidence? I think not...
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.
page 1 of 1
Comments: 2 | Views: 5128
Microsoft Communities