Reputation: 379
I am trying to append a timestamp to my URL which is called by AJAX every 5 seconds. I am doing this to stop caching in Internet Explorer browsers. However the AJAX call appears to be not calling now but there are no errors....
This code works
<script>
function loaddoc()
{
var xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("trainblock").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","networkgettrainsleicester.php",true);
xmlhttp.send();
}
</script>
With the extra code to append the timestamp does not work
<script>
function loaddoc()
{
var xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("trainblock").innerHTML=xmlhttp.responseText;
}
}
d=new Date();
xmlhttp.open("GET","networkgettrainsleicester.php+'?'+d.getTime()",true);
xmlhttp.send();
}
</script>
Any help appreciated Thanks
Upvotes: 1
Views: 5642
Reputation: 2008
You not appending the time-stamp. You are including it as a string
xmlhttp.open("GET","networkgettrainsleicester.php+'?'+d.getTime()",true);
Change to
xmlhttp.open("GET","networkgettrainsleicester.php?t=" + d.getTime(),true);
Upvotes: 5