Home  >  Article  >  Web Front-end  >  Understanding the xmlHttp object_basic knowledge

Understanding the xmlHttp object_basic knowledge

WBOY
WBOYOriginal
2016-05-16 18:11:50948browse

1 xmlHttp is a set of APIs that transmit or receive XML and other data through the Http protocol in JavaScript scripting language.

(xmlHttp is a set of APIs that transmit and receive data through the Http protocol.)

2 xmlHttp provides a protocol for the client to communicate with the http server. The client sends a request to the http server through the xmlHttp object (MSXML2.XMLHTTP.3.0) and uses DOM to process the response.

 2.1 The creation method of xmlHttp object distinguishes IE browsers and non-IE browsers:

Example: Create an xmlHttp object, request an xml document from the server, and display the document after it is returned. Below are examples of IE and non-IE respectively

 1) IE browser uses ActiveXObject method to create xmlHttp object:

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

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

xmlHttpReq.send();

alert(xmlHttpReq.responseText);

2) Non-IE browsers use XMLHttpRequest to create xmlHttp objects:

 var xmlHttpReq = new XMLHttpRequest();

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

xmlHttpReq.send();

alert(xmlHttpReq.responseText);

 2.2 After creating the XMLHttp object, because it is a set of API, it has many methods and attributes, such as open(), send(), and responseText used above.

The code processing method of xmlHttp object is relatively fixed. Therefore, all you need to do next is to understand it in the order of examples.

3 The biggest advantage of xmlHttp is that updating part of the page does not require refreshing the entire page.

Statement:
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