javascript - Append Timestamp to Ajax URL GET - Stack Overflow

I am trying to append a timestamp to my URL which is called by AJAX every 5 seconds. I am doing this to

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745233582a4617783.html

相关推荐

  • javascript - Append Timestamp to Ajax URL GET - Stack Overflow

    I am trying to append a timestamp to my URL which is called by AJAX every 5 seconds. I am doing this to

    11小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信