admin管理员组

文章数量:1415467

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

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

Share Improve this question asked Mar 25, 2017 at 13:45 user2635961user2635961 3795 silver badges20 bronze badges 2
  • because that is not appending a timestamp. Wrong quotes... ("GET","networkgettrainsleicester.php?" + d.getTime(), true) – epascarello Commented Mar 25, 2017 at 13:47
  • Tried this but IE still not updating – user2635961 Commented Mar 25, 2017 at 13:59
Add a ment  | 

1 Answer 1

Reset to default 5

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);

本文标签: javascriptAppend Timestamp to Ajax URL GETStack Overflow