This blog has moved here: woorkup.com
Tuesday, November 6, 2007

How to solve Internet Explorer cache issue in Ajax

This is a frequent asked question which can be solved simply with a line of code with javascript.

The problem
If you use Internet Explorer you can find an annoying problem when you send multiple requests using Ajax. All new requests after the first request (using http.open method), mantain the same value of the first request. This problem is caused by Internet Explorer use of cache.

Solution

When you call the method:

http.open


add a random variable using Math object and add it in the method's URL argument, for example:

nocache = Math.random();
http.open('get', 'page.php?url_parameter='+parameter+'&nocache = '+nocache);


In this way all the new request will have an URL parameter (&nocache) which force the browser to "refresh" the old value with the new value.

blog comments powered by Disqus
Artx, from LV said...

Thank you wery much !!

Anonymous said...

Thank you very much!!! You are my hero for today!!! I have killed entire day for resolving this issue..........................................

Anonymous said...

Thank you from Finland!

Macchick said...

You rock!!!!!
Note to others: I'm using the YUI connector, so the only thing I had to do was to add the nocache to my url string for the GET before calling the asyncRequest method.
--macchick

Anonymous said...

Thanks a lot!

Diego Sanchez said...

Muchas gracias!

Anonymous said...

Thanks bro!...

Anonymous said...

Thank you very much from Japan!

Anonymous said...

thanks from india

Jonas Karlsson said...

A saviour! Thanks!

Rox said...

You are a star!

  • Twitter Follow woork on Twitter
  • RSS Feed Subscribe to stay up to date
  • Podcast Coming soon...
  • 0 delicious lovers save
Support this blog with a micro subscription
If you like this blog you can contribute with a micro subscription via PayPal.
Share your links. Do you want to suggest any interesting link about web design or tech news? Submit your link.
Submit a News
Web Templates
Stock Vectors
THE CSS AWARDS