使用 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>


相关文章:

  • 2021-10-08
  • 2022-12-23
  • 2021-08-19
  • 2022-12-23
  • 2022-12-23
  • 2022-01-28
  • 2022-12-23
  • 2021-10-23
猜你喜欢
  • 2022-02-02
  • 2021-12-04
  • 2022-02-13
  • 2021-06-22
  • 2021-11-16
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案