I have this code:
$.post("php/tagNotifUnsub.php", $("#tagNotifUnsub").serialize(), function(){
$('#tagSubDiv').load('tags.php #tagSubDiv', function(){$( "button, input:submit, input:button, a#jql, input:radio" ).button();});
});
I understand that $.post is just another name for $.ajax. And I know $.ajax has caching on by default. I want it to be uncached. How can I do that?
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.
Conclusion. Developer should set cache=false to each ajax request to avoid catastrophic effect in production environment for support to legacy browsers and operating systems.
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.
cache:true is the default and does not always get the content from the cache. The cache-ability of an item on the browser is determined by: The response headers returned from the origin web server. If the headers indicate that content should not be cached then it won't be.
$.post
is not cached.
Pages fetched with POST are never cached, so the cache and ifModified options in jQuery.ajaxSetup() have no effect on these requests.
From http://api.jquery.com/jQuery.post/
Partly right, Daniel A. White!
On devices running iOS6 and Safari, POST is also cached.
What you can do is the following:
$.ajaxSetup({
type: 'POST',
headers: { "cache-control": "no-cache" }
});
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