XMLHttpRequest对象介绍——1

  熟悉XMLHttpRequest对象是学习Ajax技术的第一步。XMLHttpRequest属于Javascript对象。

XMLHttpRequest对象的基本属性和方法:

    open():建立到服务器的新请求。

    send():向服务器发送请求。

    abort():退出当前请求。

    readyState:提供当前HTML的就绪状态。

    responseText:服务器返回的请求相应文本。

XMLHttpRequest的属性和方法都和请求/响应模型有关。

XMLHttpRequest得到了现代浏览器的较好支持,但在IE5和IE6中必须使用特定于IE的ActiveXObject()构造函数。

XMLHttpRequest对象的创建

<script language="javascript" type="text/javascript">

  var request;

  function createRequest(){

  try{

      request=new XMLHttpRequest();

    }catch(trymicrosoft){

      try{

          request=new ActiveXObject("Msxml2.XMLHTTP");

        }catch(othermicrosoft){

          try{

              request=new ActiveXObject("Microsoft.XMLHTTP");

            }catch(failed){

              request=false;

            }

        }

    }

    if(!request)

      alert("Error initializing XMLHttpRequest!");

}

</script>

这个创建XMLHttpRequest对象的方法适用于大多数浏览器。

原文地址:https://www.cnblogs.com/softlin/p/1829876.html