ajax定时调用数据

<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");?>

    A+
发布日期:2009年10月24日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: