I can get the text file data from Apache but not the xml file data. Both files are in the same place on C:\xampp\htdocs \mdata. The code for the xml data is this:
Code:
<!DOCTYPE html> <html> <head> <title>Ajax Lesson</title> <script>
function getDataFromXml(){
var xmlhttp;
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
} else{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
xmldata = xmlhttp.responseXML;
var movies = xmldata.getElementsByTagName("movie");
var output="";
output += movies[0].getElementsByTagName('title')[0].firstChild.nodeValue;
document.getElementById("data").innerHTML = output;
}
}
xmlhttp.open("GET","movies.xml", true);
xmlhttp.send();
}
</script> </head> <body> <div id="data"><h2>Replace this text</h2></div> <button type="button" onclick="getDataFromXml()">Get Data</button> </body> </html>
Comment