Mar 06
Internet Explorer and a few other browsers cache GET requests for faster browsing. Good for normal pages. Bad for AJAX. So, for repeated AJAX requests, you will get a cached data instead of the actual response from the server-side. (Firefox, the prince of browsers does not seem to have this problem).
Two Options come up for this problem.
1) Use POST method for AJAX requests or
2) Just append some dummy parameter which has a different value for different GET requests. Just gives the browser an impression that its a fresh request.
So, Instead of this
var url = ‘getProducts.jsp?productId=123′
use this:
var url = ‘getProducts.jsp?productId=123′ + “&dummy=” + new Date().getTime();
Tags: ajax, caching in IE















March 14th, 2007 at 3:52 pm
Hi!
Recently I’ve got this problem.
One solution would be to send some headers before loading the ajax GET page.
Ex.
header(”Cache-control: private, no-cache”);
header(”Expires: Mon, 26 Jun 1997 05:00:00 GMT”);
header(”Pragma: no-cache”);
March 14th, 2007 at 11:00 pm
Thanks a lot for your inputs Victor.
As always, IE has another bug for this header setting. So, IE requires your code to be put in the bottom of the page too.. after the body tag.
[ page stuff here ]