Skip to content

Instantly share code, notes, and snippets.

@danielgreen
Created May 29, 2013 14:48
Show Gist options
  • Save danielgreen/5670854 to your computer and use it in GitHub Desktop.
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.
// 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