Ajax实例

来源:互联网 发布:社工库查询软件 编辑:程序博客网 时间:2024/05/17 23:27

 <script type="text/javascript">
    var xmlHttp;
    function createXMLHttpRquest()
    {
      if(window.ActiveXobject)
      {
       xmlHttp=new ActiveXobject("MicrosoftXMLHTTP");
      }
      else if(window.XMLHttpRequest)
      {
        xmlHttp=new XMLHttpRequest();
      }
    }
    function startRequest()
    {
      createXMLHttpRquest();
      xmlHttp.onreadystatechange=handleStateChange;
      xmlHttp.open("GET","response.txt",true);
      xmlHttp.send(null);
    }
    function handleStateChange()
    {
      if(xmlHttp.readyState==4)
      {
        if(xmlHttp.status==200)
        {
          alert("来自服务器的响应:"+xmlHttp.responseText);
        }
      }
    }
    </script>

原创粉丝点击