<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 strict//en"
"Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
<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 = = | | xmlhttp.status = 0) {
Get the DOM object for XML
var xmldom = Xmlhttp.responsexml;
Get the root of an XML document
var root = xmldom.documentelement;
Try
{
Get <info> Results
var info = root.getelementsbytagname (' info ');
Show return results
Alert ("Responsexml ' s value:" + info[0].firstchild.data);
}catch (Exception)
{
}
}
}
}
</script>
<body>
<div>
<input type= "button" value= "return ajax Responsexml ' s value"
Onclick= "Startrequest ();"/>
</div>
</body>
Server.xml
Copy Code code as follows:
<?xml version= "1.0" encoding= "GB2312"?>
<root>
<info>hello world!</info>
</root>