Created
May 29, 2013 14:48
-
-
Save danielgreen/5670854 to your computer and use it in GitHub Desktop.
Prevent Ajax GET and HEAD calls from receiving cached results.
This approach appends a timestamp to the query string to defeat web server caching. See http://api.jquery.com/jQuery.ajax and http://api.jquery.com/jQuery.ajaxSetup.
Another approach is to amend server-side code to set an HTTP header such as Expires.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Disable caching globally, for all Ajax requests | |
$.ajaxSetup ({ | |
cache: false | |
}); | |
// Make an Ajax request with caching explicitly disabled | |
$.ajax({ | |
type: "GET", | |
cache: false, | |
url: "http://example.com/GetSomeData" | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment