Forum Moderators: open
<input type="checkbox" name="highmark" onclick="loadFile('highmark.php?<?php echo $random; ?>')"> it's only really to test whether its a caching problem though. if it is a caching problem then you can either leave it like that, or put some php headers on the highmark.php page to stop it being cached.
[url=http://www.php.net/header]header[/url]("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
Just note these headers must come before any content is output to the screen. This includes HTML as well as white space.
function loadFile(targetFile) {
var day = new Date();
var id = day.getTime();
targetFile += '?'+id;
var elem = document.createElement("script");
elem.setAttribute("src", targetFile);
document.getElementsByTagName("body")[0].appendChild(elem);
}
The JavaScript could be simplified a little to this:
function loadFile(targetFile) {
targetFile += '?ck=' + (new Date()).getTime();
var elem = document.createElement("script");
elem.setAttribute("src", targetFile);
document.getElementsByTagName("body")[0].appendChild(elem);
}
Note, I eliminated variables that were not needed (only used once) and I also added "ck=" before the value (ck stands for cache killer). I prefer not to pass numeric values without passing them as a key/value pair... personal preference. :)
[edited by: Fotiman at 4:26 pm (utc) on July 3, 2008]