callback function
function callback () {
alert (xmlhttp.readystate);
5. Receive response data
Determining the state of an object is an interactive completion
if (xmlhttp.readystate = = 4) {
To determine if HTTP interaction is successful
if (Xmlhttp.status = = 200) {
To receive the DOM object of an XML data object using the Responsexml method
var domobj = Xmlhttp.responsexml;
if (domobj) {
<message>123123123</message>
The DOM uses getElementsByTagName to get the element node based on the tag name, and returns an array
var messagenodes = domobj.getelementsbytagname ("message");
if (Messagenodes.length > 0) {
Get the text content in the message node
The text in the message label is the byte point of the element node corresponding to the message label in the DOM, and FirstChild can get to the first child node of the current node
You can get to the node that corresponds to the text content in the following ways
var textnode = Messagenodes[0].firstchild;
For text nodes, you can return the text content of a text node in a nodevalue way
var responsemessage = Textnode.nodevalue;
Display data on a page
Find the element node for the DIV tag through the DOM
var divnode = document.getElementById ("result");
To set the HTML content in an element node
divnode.innerhtml = Responsemessage;
} else {
Alert ("XML data format error, original text content:" + xmlhttp.responsetext);
}
} else {
Alert ("XML data format error, original text content:" + xmlhttp.responsetext);
}
} else {
Alert ("Error!!! ");
}
}
}