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
The ajaxSetup() method in jQuery is used to set the default values for future AJAX requests. Syntax: $.ajaxSetup( {name:value, name:value, ... } )
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With