How to set cache false for getJSON in jQuery

+1 vote

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.

May 29, 2020 in JQuery by kartik
• 37,510 points
2,458 views

2 answers to this question.

0 votes

Hello @kartik,

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!!

answered May 29, 2020 by Niroj
• 82,880 points
0 votes
You can't pass any configuration parameters to $.getJSON. As the documentation states, it is a shorthand function for this:

$.ajax({
  dataType: "json",
  url: url,
  data: data,
  success: success
})
So you could just use that code and then set cache: false or set it globally with $.ajaxSetup.
answered Oct 7, 2020 by Amit
• 140 points

Related Questions In JQuery

0 votes
1 answer

How to check if button is disabled in jQuery Mobile?

Hello, you can try $("#deliveryNext").is(":disabled") The following code works for ...READ MORE

answered May 29, 2020 in JQuery by Niroj
• 82,880 points
4,066 views
0 votes
1 answer

How to prevent multiple selection in jQuery UI Selectable plugin?

Hii @kartik, What I did is that I allow multiple ...READ MORE

answered May 30, 2020 in JQuery by Niroj
• 82,880 points
932 views
0 votes
1 answer

How to Get Currently Selected Tab Index In jQuery UI Tabs?

Hello @kartik, If you need to get the ...READ MORE

answered Sep 10, 2020 in JQuery by Niroj
• 82,880 points
17,155 views
0 votes
1 answer

How to pass parameters in GET requests with jQuery?

Hello @kartik, Use data option of ajax. You ...READ MORE

answered Oct 5, 2020 in JQuery by Niroj
• 82,880 points
6,321 views
0 votes
1 answer

Uncaught Error: Bootstrap's JavaScript requires jQuery

Hello @kartik, You have provided wrong order for ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,880 points
22,325 views
0 votes
1 answer

How to make Bootstrap popover Appear/Disappear on hover instead of click?

Hello @kartik, Set the trigger option of the popover to hover instead ...READ MORE

answered May 12, 2020 in JQuery by Niroj
• 82,880 points
2,922 views
0 votes
1 answer

How to enable Bootstrap tooltip on disabled button?

Hii @kartik, You can wrap the disabled button ...READ MORE

answered May 12, 2020 in JQuery by Niroj
• 82,880 points
4,638 views
0 votes
1 answer

From php returning JSON to JavaScript

Hii @kartik, You can use Simple JSON for PHP. ...READ MORE

answered Jun 5, 2020 in Java-Script by Niroj
• 82,880 points
728 views
0 votes
1 answer

How to set cache false for getJSON in jQuery?

Hello @kartik, Your code just needs a trigger ...READ MORE

answered May 12, 2020 in JQuery by Niroj
• 82,880 points
692 views
0 votes
1 answer

How to pass parameters in GET requests with jQuery?

Hello, Here is the syntax using jQuery $.get $.get(url, data, ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,880 points
41,358 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP