AJAX 无刷新显示时间

   <script language="javascript" type="text/javascript">
    function btnClick()
    {
       var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); //创建XMLHTTP对象
       if(!xmlhttp)
       {
         alert("创建xml异常");
         return false;
       }
       xmlhttp.open("POST","GetDateTime.ashx?ts"+new Date(),false); //准备向服务器需要的页面发出请求
       
       
//XMLHTTP默认不是同步请求,open方法不想WebClient的DownString方法那样等服务器返回数据时才拿到,
       
//是异步的,需要监听onreadystatechange事件
       xmlhttp.onreadystatechange=function()
       {
          if(xmlhttp.readyState==4)
          {
             if(xmlhttp.status==200)
             {
               document.getElementById("Text1").value=xmlhttp.responseText;  //得到服务器返回的文本信息
             }
             else
             {
               alert("AJAX服务器返回错误");
             }
          }
       }
       xmlhttp.send(); //开始发送请求
    }
    </script>
原文地址:https://www.cnblogs.com/hishanghai/p/2578332.html