ajax定时调用数据

发布时间:2009-10-24 13:46:51 阅读:1090次

<script language=javascript>
function createXMLHttpRequest() {
   if (window.XMLHttpRequest) {//Mozilla
  xmlHttp = new XMLHttpRequest();
   }
  else if (window.ActiveXObject) {//IE
  try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); 
  } catch (e) {
  try {
  xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
  } catch (e) {}
  }
  }
}

function readjs(){
    createXMLHttpRequest();
 xmlHttp.open("get","readjs.php?fresh="+Math.random(),true);
 xmlHttp.onreadystatechange = function(){
 if(xmlHttp.readyState==4){
 document.getElementById("js").innerHTML = xmlHttp.responseText;
 }
 else{

    }
 }
 xmlHttp.send(null); 
window.setTimeout("readjs()",3000);
}
</script>
<body onload=readjs()>
<span id=js></span>
</body>

readjs.php

<?php echo date("H:i:s");?>

如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术

支付宝 微信

有疑问联系站长,请联系QQ:QQ咨询
上一篇:js轮播
下一篇:js打分效果

转载请注明:ajax定时调用数据 出自老鄢博客 | 欢迎分享