How to use XMLHttpRequest
In this article I am going to tell about XMLHttpRequest.
Definition
XMLHttpRequest (XHR) is an API available in web browser scripting languages such as JavaScript. It is used to send HTTP or HTTPS requests directly to a web server and load the server response data directly back into the script. XMLHttpRequest has an important role in the Ajax web development technique. It is currently used by many websites to implement responsive and dynamic web applications. Examples of these web applications include Gmail, Google Maps, Facebook and many others.
Supporting Browsers
Internet Explorer, Mozilla Firefox, Google Chrome, Safari and Opera are the supporting browsers.
Example
<html>
<body>
<script type="text/javascript">
window.XMLHttpRequest
{
xmlhttp=new XMLHttpRequest();
}
xmlhttp.open("GET","list.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
document.write("<table border='1'>");
var x=xmlDoc.getElementsByTagName("Bike");
for (i=0;i<x.length;i++)
{
document.write("<tr><td>");
document.write(x[i].getElementsByTagName("Model")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("Price")[0].childNodes[0].nodeValue);
document.write("</td></tr>");
}
document.write("</table>");
</script>
</body>
</html>
|
Link File
<?xml version= "1.0"?>
<inventory>
<bikes>
<model>Mountain Bike
<price>$220.00 </price>
</model>
<model>Cruiser Bike
<price>$180.00 </price>
</model>
</bikes>
</inventory>
|
Output
Further Readings
You may also want to read these related articles
Ask Your Question
Got a programming related question? You may want to post your question here
Programming Answers here