Home > Web Front-end > JS Tutorial > body text

对xmlHttp对象的理解_基础知识

WBOY
Release: 2016-05-16 18:11:50
Original
909 people have browsed it

1 xmlHttp是一套在JavaScript脚本语言中通过Http协议传送或者接收XML及其他数据的API。

(xmlHttp是一套API,通过Http协议进行数据的传送和接收。)

2 xmlHttp提供客户端同http服务器通讯的协议,客户端通过xmlHttp对象(MSXML2.XMLHTTP.3.0),向http服务器发送请求,使用DOM处理回应。

  2.1 xmlHttp对象的创建方式区分IE浏览器和非IE浏览器:

    例子:创建一个xmlHttp对象,并向服务器请求一个xml文档,返回文档后显示。下面分别就IE和非IE进行实例讲解

    1)  IE浏览器使用ActiveXObject方式创建xmlHttp对象:

      var  xmlHttpReq = new ActiveXObject("MSXML2.XMLHTTP.3.0");

      xmlHttpReq.open("GET", "http://localhost/test.xml", false);

      xmlHttpReq.send();

      alert(xmlHttpReq.responseText);

    2)  非IE浏览器使用XMLHttpRequest方式创建xmlHttp对象:

      var  xmlHttpReq = new XMLHttpRequest();

      xmlHttpReq.open("GET", "http://localhost/test.xml", false);

      xmlHttpReq.send();

      alert(xmlHttpReq.responseText);

  2.2  创建完XMLHttp对象以后,因为它是一套API,所以它有很多的方法和属性,如上面用到的open()、send()、responseText。

    xmlHttp对象的代码处理方式比较固定。因此下面要做的就只是按例子顺序进行理解就可以了。

3  xmlHttp的最大好处是更新页面的部分内容不需要刷新整个页面。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!