How to set cache false for getJSON in jQuery?

Abhinav picture Abhinav · Nov 15, 2012 · Viewed 64.5k times · Source

I am using getJSON to fetch the results from server side but facing browser cache problems. I want the cache to be false. I tried using this just before my getJSON call.

 $.ajaxSetup({
                cache: false
            })

But I am not getting the expected results. It still shows the old results.

I also identified some other solutions such as using .ajax but I really don't want to use that.

Answer

bonesnatch picture bonesnatch · Dec 3, 2012

Your code just needs a trigger for it to be enabled.

This will allow you to disable cache in all future ajax

$(document).ready(function() {
  $.ajaxSetup({ cache: false });
});

Hope it helps :)