Load an XML file with XML HTTP
When you send a xmlhttprequest to retrieve data, the user clicks a button.
<script type= "Text/javascript" >
var xmlhttp;
function Loadxmldoc (URL)
{
Xmlhttp=null;
if (window. XMLHttpRequest)
{//code for IE7, Firefox, Opera, etc.
Xmlhttp=new XMLHttpRequest ();
}
else if (window. ActiveXObject)
{//code for IE6, IE5
Xmlhttp=new ActiveXObject ("Microsoft.XMLHTTP");
}
if (xmlhttp!=null)
{
Xmlhttp.onreadystatechange=state_change;
Xmlhttp.open ("Get", url,true);
Xmlhttp.send (NULL);
}
Else
{
Alert ("Your browser does not support XMLHTTP.");
}
}
function State_change ()
{
if (xmlhttp.readystate==4)
{//4 = "Loaded"
if (xmlhttp.status==200)
{//= "OK"
document.getElementById (' A1 '). Innerhtml=xmlhttp.status;
document.getElementById (' A2 '). Innerhtml=xmlhttp.statustext;
document.getElementById (' A3 '). Innerhtml=xmlhttp.responsetext;
}
Else
{
Alert ("Problem Retrieving XML Data:" + Xmlhttp.statustext);
}
}
}
</script>
<body>
<p><b>Status:</b>
<span id= "A1" ></span>
</p>
<p><b>status text:</b>
<span id= "A2" ></span>
</p>
<p><b>Response:</b>
<BR/><span id= "A3" ></span>
</p>
<button onclick= "Loadxmldoc (' Note.xml ')" >get xml</button>
</body>
Get the results.
Using the HttpRequest Object
Status: A
Status Text: OK
Response:
Tove Jani reminder Don ' t forget me this weekend!