Fixing the jQuery AJAX Page Caching Problem
Posted: Tue Nov 25, 2008 9:17 pm
You may experience in certain browsers, or certain browser versions even, where you use jQuery's .load() event or other AJAX call to pull back a page from a server and load it into a DIV or something, and the page is cached instead of getting the latest copy. Of course, unfortunately headers are already sent when you do that, so you can't turn fix the page cache through a header() call in the PHP of that page. Turns out, this is a common problem. The fix is this:
You'd think that would be off by default with jQuery, but not so!
Code: Select all
$().ready(function(){ //when page has fully loaded
$.ajaxSetup ({
// Disable caching of AJAX responses */
cache: false
});
});