My table is empty and I can't figure out where the mistake is. I want to use the console to debug, but I'm not sure how.
Update: I found a working sample here http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_xml2. I used similar code, but with different XML data and it's not working. I don't understand why.
https://i.stack.imgur.com/jYmM6.png
<!DOCTYPE html>
<html>
<head>
<title>XML Data Block Demo</title>
<style>
table, th, td {
border: 1px solid black;
border-collapse:collapse;
}
th, td {
padding: 5px;
}
</style>
<script>
function parseXML(input) {
var xml = input.responseXML;
var parser = new DOMParser();
var doc = parser.parseFromString(xml, "application/xml");
var lineItems = doc.getElementsByTagName("Stock");
var table="<tr><th>Ticker</th><th>Price</th></tr>";
for (i = 0; i <lineItems.length; i++) {
table += "<tr><td>" +
lineItems[i].getElementsByTagName("Ticker")[0].childNodes[0].nodeValue +
"</td><td>" +
lineItems[i].getElementsByTagName("Price")[0].childNodes[0].nodeValue +
"</td></tr>";
}
document.getElementById("table").innerHTML = table;
}
function loadXML() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
parseXML(xhttp);
}
};
xhttp.open("GET", "http://localhost/ajax/xml/demo1/stocks.xml", true);
xhttp.send();
}
</script>
</head>
<body onload="loadXML()";>
<table id="table"></table>
</body>
</html>