CopyCode The Code is as follows: <! Doctype HTML public "-// W3C // dtd xhtml 1.0 strict // en"
Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd>
<HTML>
<Head>
<Title> Ajax Hello World </title>
<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 root = xmldom.doc umentelement;
Try
{
// Obtain the <info> result
VaR info = root. getelementsbytagname ('info ');
// Display the returned results
Alert ("responsexml's value:" + info [0]. firstchild. data );
} Catch (exception)
{
}
}
}
}
</SCRIPT>
</Head>
<Body>
<Div>
<Input type = "button" value = "Return Ajax responsexml's value"
Onclick = "startrequest ();"/>
</Div>
</Body>
</Html>
Server. xml
Copy codeThe Code is as follows: <? XML version = "1.0" encoding = "gb2312"?>
<Root>
<Info> Hello world! </INFO>
</Root>