ajax轮循

使用 AJAX 进行异步加载轮询操作。简单代码如下:

<script>

// 执行ajax轮循操作
function polling(){
var xmlhttp;
// 判断浏览器--创建对象
if ( window.XMLHttpRequest ){
xmlhttp = new XMLHttpRequest();
}else{
xmlhttp = new ActiveXObject( "Microsoft.XMLHTTP" );
}
// 与服务器建立连接
xmlhttp.open( "GET", "polling.php", true );
// 发送请求
xmlhttp.send();
// 监听事件 回调匿名函数 判断返回值
xmlhttp.onreadystatechange = function(){
if ( xmlhttp.status == 200 && xmlhttp.readyState ==4 ){
alert( xmlhttp.responseText );
}
}
}
setInterval( "polling()", 1000 );

</script>


原文地址:https://www.cnblogs.com/laowenBlog/p/5944823.html