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

misc1Just wanted to make a quick post about something that was annoying me today and I learned how to fix it.

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 });

Hope you find this useful.

2 comments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s