<Html> <Script type = "text/javascript">
Var xmlHttp;
Function createXMLHttpRequest ()
{
If (window. ActiveXObject)
{
XmlHttp = new ActiveXObject ("Microsoft. XMLHTTP ");
}
Else if (window. XMLHttpRequest)
{
XmlHttp = new XMLHttpRequest ();
}
}
Function startRequest ()
{
CreateXMLHttpRequest ();
Try
{
XmlHttp. onreadystatechange = handleStateChange;
XmlHttp. open ("GET", "data. xml", true );
XmlHttp. send (null );
}
Catch (exception)
{
Alert ("The resource you want to access does not exist! ");
}
}
Function handleStateChange ()
{
If (xmlHttp. readyState = 4)
{
If (xmlHttp. status = 200 | xmlHttp. status = 0)
{
// Retrieve the xml dom object
Var xmlDOM = xmlHttp. responseXML; // get the root of the XML document
// Var res = document. getElementById ("res ");
// Res.innerhtml#xmldom.doc umentElement;
Var root = xmlDOM.doc umentElement;
Try
{// Obtain the <info> result
Var info = root. childNodes; // The returned result is displayed.
For (var I = 0; I <info. length; I ++) // traverses the output
Alert ("responseXML's value:" + info [I]. text );
}
Catch (exception)
{}
}
}
}
</Script> <Div id = "res"> </div> </body> Data. xml <? Xml version = "1.0" encoding = "GB2312"?>
<Root>
Fff
<Info> hello world! </Info>
<Goods> hello1 </goods>
<Goods> hello2 </goods>
</Root>