【发布时间】:2013-06-11 03:47:33
【问题描述】:
我需要显示来自这个 URL 的 XML 数据:http://api.redfoundry.com/RFBase.ashx?type=get&name=b39d11d5-505f-453e-bcfc-9d3b19dd8a61&key=2469F6F56F61976FB51FDEC878E93555
进入一个 HTML 表格,当 HTML 页面被访问时会自动加载。
到目前为止,我得到了以下内容,但它似乎不起作用,它来自 W3 教程:
<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>
我想在表格中显示的结果是“项目 ID”、地名、描述和地址。
【问题讨论】:
-
“它似乎不起作用”,请更具体一点,有什么问题吗?你有任何控制台错误吗?
-
HTML 中根本没有显示任何内容。实际上,该网站只是空白。
标签: javascript html xml html-table