At this point, you can send a request to read the XML data on the server. The last thing to do is to process the data. For more information About XMLHttpRequest objects, see the document About XMLHttpRequest Object.
Example:
// AjaxDemo.html
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> Asynchronous JavaScript And XML </title>
</Head>
<Body>
<Script type = "text/javascript">
Var xmlHttp = null;
Function readyStateChangeHandle ()
{
If (xmlHttp. readyState = 4)
{
If (xmlHttp. status = 200)
{
Var xmlDOM = xmlHttp. responseXML;
Var xmlRoot=xmlDOM.doc umentElement;
Try
{
Var xmlItem = xmlRoot. getElementsByTagName ("item ");
Alert (xmlItem [0]. firstChild. data );
}
Catch (e)
{
Alert (e. message );
}
}
}
}
Function ajaxRequest ()
{
If (window. XMLHttpRequest)
{
XmlHttp = new XMLHttpRequest ();
}
Else if (window. ActiveXObject)
{
XmlHttp = new ActiveXObject ("Microsoft. XMLHTTP ");
}
XmlHttp. onreadystatechange = readyStateChangeHandle;
XmlHttp. open ("GET", "data. xml", true );
XmlHttp. send (null );
}
</Script>
<Input type = "button" onclick = "ajaxRequest ()" value = "Take me to the world of AJAX"/>
</Body>
</Html>
// Data. xml
<? Xml version = "1.0" encoding = "GB2312"?>
<Root>
<Item> Welcome to the world of AJAX (Asynchronous JavaScript And XML )! </Item>
</Root>