Why is jQuery call ‘getJSON()’ returning cached data?
Just 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.
Thanks a lot!
LikeLike
I am glad to know that you found it useful.
LikeLike