ホームページ >バックエンド開発 >PHPチュートリアル >Ajax テクノロジーが常にステータスを送信する、その解決方法
ajax 技术 開始终出去送信状態态
ajax.js代码:
var xmlHttp;
function S_xmlhttprequest(){
if(window.ActiveXObject){
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(widow.XMLHttpRequest){
xmlHttp=new XMLHttpRequest();
}
}
function funphp100(url){
S_xmlhttprequest();
xmlHttp.open("GET","for.php?id= url,true);
xmlHttp.onreadystatechange=byphp;
xmlHttp.send(null);
}
function byphp(){
if(xmlHttp.readyState==1){
document.getElementById('php100').innerHTML="読み込み中....";
}
if(xmlHttp.readyState==4){
var byphp100 = xmlHttp.responseText;
document.getElementById('php100').innerHTML=byphp100;
}
}
for.php代码
6eb9ae4423acaa275efa0e3c7853da142cacc6d41bbb37262a98f745aa00fbf0
1002f1006c437345fef3209369dda4b8o5db79b134e9f6b82c0b36e0489ee08ed
0710f74ca45c1c39fda6e1867e13b83bt5db79b134e9f6b82c0b36e0489ee08ed
4cba8eecfbf0392c90c962d7b9df1790x5db79b134e9f6b82c0b36e0489ee08ed
0c6dc11e160d3b678d68754cc175188a
ae7db4cd1435ff29c9a87b5e85842f5116b28748ea4df4d9c2150843fecfba68
if($id=$_GET[id]){<br /> for($i=1;$i<=5;$i++){<br /> <br /> echo $i;<br /> //sleep(2);<br /> }<br /> exit();<br /> }
<html><br /> <head><br /> <title> </title> <br /> <script type="text/javascript" src='jquery-1.4.2.min.js'></script><br /> <br /> </head><br /> <script type="text/javascript"><br /> var xmlHttp;<br /> function S_xmlhttprequest(){<br /> if(window.ActiveXObject){<br /> xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");<br /> }<br /> else if(window.XMLHttpRequest){<br /> xmlHttp=new XMLHttpRequest();<br /> }<br /> }<br /> function funphp100(url){<br /> S_xmlhttprequest();<br /> xmlHttp.open("GET","test.php?id="+url,true);<br /> xmlHttp.onreadystatechange=byphp;<br /> xmlHttp.send(null);<br /> }<br /> function byphp(){<br /> if(xmlHttp.readyState==1){<br /> document.getElementById('php100').innerHTML="loading....";<br /> }<br /> if(xmlHttp.readyState==4){<br /> <br /> var byphp100 = xmlHttp.responseText;<br /> document.getElementById('php100').innerHTML=byphp100;<br /> <br /> }<br /> <br /> }<br /> <br /> </script><br /> <body><br /> <a href= "#" onclick="funphp100('o')">o</a><br /> <a href= "#" onclick="funphp100('t')">t</a><br /> <a href= "#" onclick="funphp100('x')">x</a><br /> <br><br /> <div id="php100"></div><br /> </body><br /> </html>