php ajax轮询推送,[PHP]PHP+AJAX实现轮询代码
今天碰到了一個PHP輪詢的代碼,主要是借助js的setInterval()函數實現定時輪詢的。具體代碼如下。
js代碼
function?polling(){
//執行輪詢代碼
var?xmlHttp;
if(window.XMLHttpRequest){
xmlHttp=new?XMLHttpRequest();
}else{
xmlHTTP=new?ActiveXObject("Microsoft.XMLHTTP");
}
xmlHttp.onreadystatechange=function(){
if(xmlHttp.status==200?&&?xmlHttp.readyState==4){
result=xmlHttp.responseText;
if(result=="true"){
window.location.href="welcom.php";
}
}
}
xmlHttp.open('GET',"polling.php?randnumber=123456",true);
xmlHttp.send();
}
PHP代碼
require?'mysql_connect.php';
$randnumber=$_GET['randnumber'];
$result=mysql_query("select?*?from?login_record?where?randnumber='$randnumber'");
$row=mysql_fetch_array($result);
if($row['username']!=""){
echo?"true";
}else{
echo?"false";
}
?>
總結
以上是生活随笔為你收集整理的php ajax轮询推送,[PHP]PHP+AJAX实现轮询代码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: oracle的日志分析工具,oracle
- 下一篇: linux 普通用户退出vim,Linu