Skip to content Skip to sidebar Skip to footer

Internet Explorer 7 Ajax Links Only Load Once

I'm writing an application and I'm trying to tie simple AJAX functionality in. It works well in Mozilla Firefox, but there's an interesting bug in Internet Explorer: Each of the li

Solution 1:

This happens because Internet Explorer ignores the no-cache directive, and caches the results of ajax calls. Then, if the next request is identical, it will just serve up the cached version. There's an easy workaround, and that is to just append random string on the end of your query.

 xmlHttp.open("GET","blurb.php?"+Math.random();

Solution 2:

It looks like IE is caching the response. If you either change your calls to POST methods, or send the appropriate headers to tell IE not to cache the response, it should work.

The headers I send to be sure it doesn't cache are:

Pragma:no-cacheCache-Control:no-cacheExpires:Fri,30Oct1998 14:19:41 GMT

Note the expiration date can be any time in the past.

Solution 3:

The problem is that IE does wacky things when the response handler is set before open is called. You aren't doing that for the first xhr request, but since you reuse the xhr object, when the second open is called, the response handler is already set. That may be confusing, but the solution is simple. Create a new xhr object for each request:

move the:

var xmlHttp = new XMLHttpRequest();

inside the select function.

Solution 4:

The response header that has worked best for me in the IE AJAX case is Expires: -1, which is probably not per spec but mentioned in a Microsoft Support Article (How to prevent caching in Internet Explorer). This is used in conjunction with Cache-Control: no-cache and Pragma: no-cache.

Solution 5:

In jQuery.ajax, you can set the "cache" setting to false:

http://api.jquery.com/jQuery.ajax/

Post a Comment for "Internet Explorer 7 Ajax Links Only Load Once"