将时间戳附加到 Ajax URL GET

use*_*961 1 javascript ajax internet-explorer caching

我试图在我的 URL 中附加一个时间戳,它每 5 秒由 AJAX 调用。我这样做是为了停止 Internet Explorer 浏览器中的缓存。但是 AJAX 调用现在似乎没有调用,但没有错误....

此代码有效

<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>
Run Code Online (Sandbox Code Playgroud)

使用额外的代码来附加时间戳不起作用

 <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>
Run Code Online (Sandbox Code Playgroud)

任何帮助表示感谢

Mar*_*ebb 5

您没有附加时间戳。您将其作为字符串包含在内

xmlhttp.open("GET","networkgettrainsleicester.php+'?'+d.getTime()",true);
Run Code Online (Sandbox Code Playgroud)

改成

xmlhttp.open("GET","networkgettrainsleicester.php?t=" + d.getTime(),true);
Run Code Online (Sandbox Code Playgroud)