I’ve been doing a lot of converting of web pages that required the user to refresh the page for updated content to AJAX (eliminates need to refresh). It was all good until I started receiving complaints that data was no longer refreshing in IE.

What I’m using is a AJAX get command like this:

xmlhttp.open(“GET”,”url”,true);
xmlhttp.send();

however, in Internet Explorer, the content never gets refreshed – that is, the AJAX request is getting cached. There are a number of suggested solutions, including using a POST rather than a GET and appending a random string to the request.

The best way to keep AJAX working in IE is to tell the xmlhttp object not to cache content that is older than a certain date; you can do that by changing the request in this fashion (appending 1 line):

xmlhttp.open(“GET”,”url”,true);
xmlhttp.setRequestHeader(“If-Modified-Since”, “Sat, 1 Jan 2000 00:00:00 GMT”);
xmlhttp.send();

This will solve any AJAX caching problem you might encounter. It’s a simple solution, but caused me a big headache!

Also, if you have webpages with ad code on them, each refresh is another impression and can skew your results more than you think! Move to AJAX and you’ll solve that problem :)

I hope this helps those of you playing with AJAX.

2 comment(s) need to be approved.
15 replies
  1. Conrad says:

    Ummm…why not set cache-control in the response header? The following should work very nicely Cache-Control: no-cache

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *