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
1 Answer
Reset to default 5You 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
版权声明:本文标题:javascript - Append Timestamp to Ajax URL GET - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745233581a2648929.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论