When sending a request, there is no difference between XHR with the return type of text and xml. The difference is that the callback function processes the returned data using the sample code:
The Code is as follows:
// Callback function
Function callback (){
// Alert (xmlhttp. readyState );
// 5. Receive response data
// Determine whether the object state is interactive.
If (xmlhttp. readyState = 4 ){
// Determine whether http interaction is successful
If (xmlhttp. status = 200 ){
// Use responseXML to receive DOM objects of XML Data Objects
Var domObj = xmlhttp. responseXML;
If (domObj ){
// 123123123
// Use getElementsByTagName In the dom to obtain the Element Node Based on the tag name. An array is returned.
Var messageNodes = domObj. getElementsByTagName ("message ");
If (messageNodes. length> 0 ){
// Obtain 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. firstChild can obtain the first subnode of the current node.
// The Node corresponding to the text content can be obtained through the following methods
Var textNode = messageNodes [0]. firstChild;
// For a text node, nodeValue can be used to return the text content of the text node.
Var responseMessage = textNode. nodeValue;
// Display data on the page
// Use dom to find the Element Node corresponding to the p tag
Var pNode = document. getElementById ("result ");
// Set the html content in the Element Node
PNode. 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 !!! ");
}
}
}