Heim > Web-Frontend > js-Tutorial > Hauptteil

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

WBOY
Freigeben: 2016-05-16 18:11:50
Original
908 Leute haben es durchsucht

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的最大好处是更新页面的部分内容不需要刷新整个页面。

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!