Stop AJAX pages caching

Status
Not open for further replies.

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
In this short 'tutorial' I'm going to show you how to load AJAX pages without them caching in your browser.

This can be handy if for example you are loading user's wall posts into a user profile page, or you're loading a JavaScript file into your page that has already cached.

Here is how you do it:
PHP:
$(function(){
    $("div#place_to_late_to").load("load_this_page.php?k=" + Math.random());
});

Adding the 'k=" + Math.random()' onto it makes PHP essentially load a new version of 'load_this_page.php' each time it is called so you get a totally fresh copy each time it is loaded.

This should work with almost anything and the best thing is, you don't need to handle the $_GET['k'] variable in your PHP script, unless you actually want to.

- Mark
 
Status
Not open for further replies.

Users who are viewing this thread

Top