GET IN TOUCH WITH US: +353 (0)61 514582 info@darvu.com

How to deal with Ajax Caching in IE

September 13th, 2013 Synnott Lawline Logo

Warning, this is a techie post.

I recently had an issue with Internet Explorer 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, simply disable ajax caching after page load (i.e. $(document).ready()).

[code]$(document).ready(
function() {
$.ajaxSetup({ cache: false });
});[/code]

After that, you can call $.getJSON as normal!

[code]$.getJSON(
url,
function(data) {
//do important things with your data here,
//safe in the knowledge that IE is no longer caching old responses! o/
});
});[/code]

Next Post: Marketing your business online. Part 1: Introduction Previous Post: Sort listboxes that have been populated with JSON results.
Get In Touch

Have a query? Fill out the form below and we’ll get back to you as soon as possible.