How to deal with Ajax Caching in IE
September 13th, 2013 | TechnicalWarning, this is a techie post.
I recently had an issue with Internet Explorer recently when using getJSON to get a result set from the server, however the client browser was displaying an old version of the result set. After a little digging, I found that IE caches ajax transactions by default. Personally, I think this is daft, as I generally want to request new data from the server the majority of the time. From this point of view, I think it would be better to have caching disabled by default – but there you go!
To get around this problem, simlply disable ajax caching after page load (i.e. $(document).ready()).
$(document).ready(
function() {
$.ajaxSetup({ cache: false });
});
After that, you can call $.getJSON as normal!
$.getJSON(
url,
function(data) {
//do important things with your data here,
//safe in the knowledge that IE is no longer caching old responses! o/
});
});