反而:
xmlHttpRequest.onreadystatechange=function(){
if(xmlHttpRequest.readyState == 4 && xmlHttpRequest.status == 200){
alert("Call took " + new Date().getTime() - t1 + " milliseconds");
document.getElementById("info").innerHTML = xmlHttpRequest.responseText;
}
}
xmlHttpRequest.open("GET", "showStopsInfoPopup.do?stop="+stop, true);
xmlHttpRequest.send();
尝试这个:
xmlHttpRequest.open("GET", "showStopsInfoPopup.do?stop="+stop, true);
xmlHttpRequest.onreadystatechange=function(){
if(xmlHttpRequest.readyState == 4 && xmlHttpRequest.status == 200){
alert("Call took " + new Date().getTime() - t1 + " milliseconds");
document.getElementById("info").innerHTML = xmlHttpRequest.responseText;
}
}
xmlHttpRequest.send(null);
修复新日期
在您的代码中缺少括号(请记住分开Mathematics
)Strings
。尝试:
xmlHttpRequest.open("GET", "showStopsInfoPopup.do?stop="+stop, true);
xmlHttpRequest.onreadystatechange=function(){
if(xmlHttpRequest.readyState == 4 && xmlHttpRequest.status == 200){
alert("Call took " + (new Date().getTime() - t1) + " milliseconds");
document.getElementById("info").innerHTML = xmlHttpRequest.responseText;
}
}
xmlHttpRequest.send(null);
测试
Ajax 请求:
<div id="info"></div>
<script>var xhr, t1;
if(window.ActiveXObject){
try { xhr=new ActiveXObject("Msxml2.XMLHTTP"); }catch(e){
try { xhr=new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){}
}
} else if(window.XMLHttpRequest){
xhr=new XMLHttpRequest();
}
xhr.open("GET", "teste.php", true);
t1 = new Date().getTime();//I start the timer that point to prevent the previous functions affect the end result
xhr.onreadystatechange=function(){
if(xhr.readyState == 4 && xhr.status == 200){
document.getElementById("info").innerHTML = "Call took " + (new Date().getTime() - t1) + " milliseconds";
}
}
xhr.send(null);
</script>
php (teste.php):
<?php
sleep(5);
echo 'ok';
?>
结果:
IE8:5004 毫秒
Chorme:5005 毫秒
火狐:5014 毫秒
IE7:5023 毫秒
IE6:5053 毫秒
经过测试,得出的结论可能是服务器端的某些东西,更准确地说是在您的 PHP 中。