Wednesday, January 25, 2012

IE Caches Jquery Ajax Request

Do you know what's the time now, while I write this post? It's 2:00 am in the morning. I was asked to fix a Jquery issue happening only in Internet explorer.

There was a piece of code which makes an ajax request to the server periodically. But this code only works  once.  This problem is seen only in Internet explorer. After scratching my head for a while I finally realized that IE caches ajax requests.

The solution is to use the following code:


$.ajaxSetup ({
   cache: false
});

Setting cache to false also appends a query string parameter, "_=[TIMESTAMP]", to the URL. So if you have  long query string as the ajax request this might be a problem. I am  not sure, I but I guess so.

Happy Hacking!


No comments: