Reputation: 83
I need to display the XML data from this URL: http://api.redfoundry.com/RFBase.ashx?type=get&name=b39d11d5-505f-453e-bcfc-9d3b19dd8a61&key=2469F6F56F61976FB51FDEC878E93555
into a HTML table that will automatically load when the HTML page is visited.
So far I have got the following but it doesn't seem to work, it's come from a W3 tutorial:
<html>
<body>
<script>
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","http://api.redfoundry.com/RFBase.ashx?type=get&name=b39d11d5-505f-453e-bcfc-9d3b19dd8a61&key=2469F6F56F61976FB51FDEC878E93555",false);
xmlhttp.send();
xmlDoc = xmlhttp.responseXML;
document.write("<table border='1'>");
var x = xmlDoc.getElementsByTagName("item");
for (var i=0; i<x.length; i++) {
document.write("<tr><td>");
document.write(x[i].getElementsByTagName("placename")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("description")[0].childNodes[0].nodeValue);
document.write("</td></tr>");
}
document.write("</table>");
</script>
</body>
</html>
The results that I want to show in the table are 'Item ID', placename, description, and address.
Upvotes: 0
Views: 3146
Reputation: 167516
Check the error console of your browser, it is probably telling that the access is denied. The same origin policy inside browsers usually prevents that an XMLHttpRequest can load data from a different origin than the one the document with the script is loaded from. So unless the server is set up to support CORS and you are using a browser supporting that too you can't load a document with XMLHttpRequest from the origin http://api.redfoundry.com.
Upvotes: 1