jqueryjquery-uigetjsonbrowser-cache

How to set cache false for getJSON in jQuery?


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.


Solution

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