I have a ajax script which calls the content of another webpage and just displays the content in a alert (its just the unix timestamp). Even though the time is changing, ajax does not report the new time until I load the page in my browser. How can I keep this so it does not cache the page? I need it to load a new version everytime.
Main Page - test.php
Requested Page - test2.php
Main Page - test.php
Code:
<SCRIPT language=JavaScript type=text/javascript>
function createXHR()
{
var request = false;
try {
request = new ActiveXObject('Msxml2.XMLHTTP');
}
catch (err2) {
try {
request = new ActiveXObject('Microsoft.XMLHTTP');
}
catch (err3) {
try {
request = new XMLHttpRequest();
}
catch (err1)
{
request = false;
}
}
}
return request;
}
function loadHTML(theURL)
{
var xhr = createXHR();
xhr.onreadystatechange=function()
{
if(xhr.readyState == 4)
{
if(xhr.status == 200)
{
SessionTimeout = xhr.responseText;
}
}
};
xhr.open("GET", theURL , true);
xhr.send(null);
alert(SessionTimeout);
}
var SessionTimeout = "";
</SCRIPT>
<INPUT type="BUTTON" value="Read Timestamp" ONCLICK="loadHTML('test2.php')"></p>
Code:
<? echo time(); ?>
Comment