CopyCode The Code is as follows: // import the JS File
Function getresult (URL, ready ){
VaR XMLHTTP;
VaR r = function (){
If (XMLHTTP. readystate = 4 ){
If (XMLHTTP. Status = 200 ){
// Alert (isie );
VaR xmlstr;
VaR xmldoc;
VaR isie = !! (Window. attachevent &&! Window. Opera );
If (isie)
Xmldoc = XMLHTTP. responsexml;
Else {
Xmlstr = XMLHTTP. responsetext;
Alert (xmlstr );
VaR parser = new domparser ();
Xmldoc = parser. parsefromstring (xmlstr, "text/XML ");
}
Try {
Ready (xmldoc );
} Catch (e ){
Alert (E. Message );
}
}
}
}
VaR create = function (URL, R ){
Try {
// Firefox, opera 8.0 +, Safari
XMLHTTP = new XMLHttpRequest ();
} Catch (e ){
// Internet Explorer
Try {
XMLHTTP = new activexobject ("msxml2.xmlhttp ");
} Catch (e ){
Try {
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
} Catch (e ){
Alert ("your browser does not support Ajax! ");
Return false;
}
}
}
XMLHTTP. onreadystatechange = R;
XMLHTTP. Open ("get", URL, true );
XMLHTTP. Send (null );
}
Create (URL, R );
}
// Application
Function ready (xmldoc)
{
X = xmldoc. getelementsbytagname ("A") [1];
Y = x. childnodes [0];
TXT = Y. nodevalue;
Alert (txt );
}
Getresult ("../XML. jsp", ready );
XML:Copy codeThe Code is as follows: <r>
<A> FF </a>
<A> GGD </a>
</R>
The childnodes attribute returns the list of child nodes. <A> the element has only one subnode, that is, one text node.
The following code retrieves the text node of the <A> element:
X = xmldoc. getelementsbytagname ("A") [0];
Y = x. childnodes [0];
The nodevalue attribute returns the text value of the text node:
X = xmldoc. getelementsbytagname ("title") [0];
Y = x. childnodes [0];
TXT = Y. nodevalue;
Result: TXT = "GGD"