1. What is an XMLHTTPRequest object?
The most common definition is: XmlHttp is a set of APIs that can be transmitted or received from the http protocol in scripting languages such as Javascript, VbScript, and Jscript. The biggest use of XmlHttp is that it can update part of the content of the web page without refreshing the entire page. (This function is one of the major features of AJAX:))
Interpretation from MSDN: XmlHttp provides a protocol for the client to communicate with the http server. The client can send a request to the http server through the XmlHttp object (MSXML2.XMLHTTP.3.0) and process the response using the Microsoft XML Document Object Model (DOM).
Let me talk about some off-topics here. In fact, this thing appeared very early. It was just that the browser support was not enough and only in IE, so most WEB programmers did not use it much. But now the situation has changed a lot. Mozilla and Safari adopted it as de facto standards, and mainstream browsers have begun to support XMLHTTPRequest objects. However, it should be noted here that XMLHTTPRequest is not currently a W3C standard, so its performance is slightly different on different browsers.
2. Create XMLHTTPRequest object
By the way, when it comes to the difference, let's take a look at how to declare (used) it. Before using the XMLHTTPRequest object to send requests and process responses, we must create an XMLHTTPRequest object with javascript. (IE implements XMLHTTPRequest as an ActiveX object, while other browsers [such as Firefox/Safari/Opear] implements it as a local javascript object). Let's take a look at how to use javascript to create it:
<script language="javascript" type="text/javascript">
<!--
var xmlhttp;
// Create XMLHTTPRequest object
function createXMLHTTPRequest(){
if(window.ActiveXObject){ // Determine whether ActiveX controls are supported
xmlhttp = new ActiveObject("Microsoft.XMLHTTP"); // Create XMLHTTPRequest object by instantiating a new instance of ActiveXObject
}
else if(window.XMLHTTPRequest){ // Determine whether XMLHTTPRequest is implemented as a local javascript object
xmlhttp = new XMLHTTPRequest(); // Create an instance of XMLHTTPRequest (local javascript object)
}
}
//-->
</script>
3. Properties and methods
Since there are too many things, now use a page to list some methods and attributes, and then give detailed examples in the future (mainly because I am also studying).
<html>
<head>
<title>Description of XMLHTTPRequest object DEMO</title>
<script language="javascript" type="text/javascript">
<!--
var xmlhttp;
// Create an XMLHTTPRequest object
function createXMLHTTPRequext()
{
if (window.ActiveXObject)
{
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
}
else if (window.XMLHTTPRequest)
{
xmlhttp = new XMLHTTPRequest();
}
}
function PostOrder(xmldoc)
{
createXMLHTTPRequext();
// Method: open
// Create a new http request and specify the method, URL and verification information of this request
// Syntax: oXMLHttpRequest.open(bstrMethod, bstrUrl, varAsync, bstrUser, bstrPassword);