Hey guys, I've looked around online and on here a fair amount in order to try and figure out what the problem with this is. I am a newbie to anything not html, and I can not figure out why this XML is not loading.
Say I just have two files, "/contact.xml" and "/xmltest.html" and I want to load the xml into the html page using javascript. Here is what I have so far.
<html>
<body>
<h1>Carney Contacts Test</h1>
<b>Name:</b> <span id="name"></span><br />
<b>Email:</b> <span id="email"></span><br />
<b>Phone:</b> <span id="number"></span>
<script type="text/javascript">
var xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","contacts.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
document.getElementById("name").innerHTML=
xmlDoc.getElementsByTagName("name")[0].childNodes[0].nodeValue;
document.getElementById("email").innerHTML=
xmlDoc.getElementsByTagName("email")[0].childNodes[0].nodeValue;
document.getElementById("phone").innerHTML=
xmlDoc.getElementsByTagName("phone")[0].childNodes[0].nodeValue;
</script>
</body>
Much of this was directly off the w3c site, and I still can not get it to work! Chrome is giving me "Uncaught TypeError: Cannot call method 'getElementsByTagName' of null", if that helps anyone.
Help appreciated!