IT
<html>
<title>ajaxStudy</title>
<body>
<script type="text/javascript">
var xmlHttp;
function CreateHttpRequest()
{
    try
    {
   // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
 catch (e)
    {

  // Internet Explorer
   try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      //ie6+
      }
   catch (e)
      {

      try
         {
         xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
         //ie5
         }
      catch (e)
         {
         alert("您的浏览器不支持AJAX!");
         return false;
         }
      }
    }
}

 function ajaxfun()
 {
     CreateHttpRequest();
     xmlHttp.onreadystatechange=function()
     {     
     if(xmlHttp.readyState==4)
     {
         document.myForm.time.value=xmlHttp.responseText;
         alert(xmlHttp.readyState);
         }
     }
     xmlHttp.open("GET","time.asp",true)    
         xmlHttp.send(null);
}
</script>


<form name="myForm">
用户: <input type="text" name="username" onKeyup="ajaxfun()"  />
时间: <input type="text" name="time" />
</form>

</body>
</html>
posted on 2010-12-23 09:45  liufei  阅读(145)  评论(0编辑  收藏  举报