Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$.ajaxSetup cache: What does that mean in jquery code

Today i have observed the following in a Jquery code:

$.ajaxSetup({ cache: false });

What does this mean? And what happens if the value of cache turns True.

Thank you in advance

like image 869
Adithya Sai Avatar asked Aug 31 '15 10:08

Adithya Sai


People also ask

What is ajaxSetup?

The ajaxSetup() method in jQuery is used to set the default values for future AJAX requests. Syntax: $.ajaxSetup( {name:value, name:value, ... } )

What is the use of cache in AJAX?

Fact #1 : Ajax Caching Is The Same As HTTP Caching At this level, the browser doesn't know or care about Ajax requests. It simply obeys the normal HTTP caching rules based on the response headers returned from the server. If you know about HTTP caching already, you can apply that knowledge to Ajax caching.

What is cache false in AJAX?

The cache: false is used by developers to prevent all future AJAX requests from being cached, regardless of which jQuery method they use. We can use $. ajaxSetup({cache:false}); to apply the technique for all AJAX functions.

What is cache true in AJAX call?

The cache is set to true by default (default: true). The cache is set to false if the dataType is 'script' or 'jsonp'. i understood cache is true by default but i many time use jquery ajax to fetch data from server side function but always get response. it means in my case nothing has been cache.


1 Answers

Read jQuery.ajax()

cache (default: true, false for dataType 'script' and 'jsonp') Type: Boolean If set to false, it will force requested pages not to be cached by the browser. Note: Setting cache to false will only work correctly with HEAD and GET requests. It works by appending "_={timestamp}" to the GET parameters. The parameter is not needed for other types of requests, except in IE8 when a POST is made to a URL that has already been requested by a GET.

like image 130
Rohan Kumar Avatar answered Sep 23 '22 09:09

Rohan Kumar