Blog

I'm looking for:

Why is jQuery call ‘getJSON()’ returning cached data?

I am working on an ASP.NET MVC application making use of the jQuery.getJSON() method to retrieve data from an MVC Controller and displaying it on my web page.  I found that the jQuery.getJSON() call was caching the data and not actually calling my MVC Controller method each time that JavaScript called the method.

    $.getJSON("/Controller/Method/",
        function (data) {
            DisplayDataOnWebPage(data);
        });

I read online that this is an issue with Internet Explorer caching data by default.  The simple solution is to call the jQuery.ajaxSetup() method passing a value of false to the cache property which causes jQuery to disable caching on ajax calls.

    $.ajaxSetup({ cache: false });

Looking for a new job? We work with some of the biggest names in tech, and we’re hiring! Check out our open jobs and make your next career move with Planet.