How to FIX AJAX & IE Caching Issue
I was developing a ajax utility in my application where it loads a form at one tab and shows the lists at another tab. Both calls from same page and i was almost done with that modules. Generally i use Firefox and Firebug to develop and fix my ajax application. Everything works fine but problem occurred when i was testing with IE. Its weired, it doesn’t load new data. It was showing from cache. IE loves to cache ajax calls. Then i set the header function with PHP, it still show cache data!!! Then i search the net and got few solution. For IE i have to send my request as POST and it would solves my problem. But as i uses same application in many places so i was stuck to use GET method. So finally i got the solution and here is the solution:
After the open the “GET” and before the send method i put the following code:
myReq.open(”GET”, url, true);
—–
myReq.setRequestHeader(”If-Modified-Since”, “Sat, 1 JAN 1970 00:00:00 GMT”);
myReq.setRequestHeader(”Cache-Control”, “no-cache”);
—–
myReq.send(null);
It was simple but it took my 2 hours before searching over net for the solution!!!