Our highest priority is to satisfy the customer through early and continuous delivery of valuable and working software.

Friday, December 21, 2007

Ajax cache problem in IE

By default IE will cache all Ajax requests. If you make a same Ajax request again without clearing cache, every time you will get same data, instead of fresh data.

So, what's the solution?

Solution: Use either the date and time or a random number in the query string to force IE to reload the relevant document.

Example:
var QueryString = "request_id=x";
var DatetimeQueryString = “&datetime=”+new Date().getTime();
var url = “request_url.php?”+QueryString+DatetimeQueryString;
httpRequest.open(”GET”, url, true);
httpRequest.onreadystatechange = update;
httpRequest.send(null);

1 comment: