我只是想获取XML数据,并使用jscript在HTML页面中显示它。据this tutorial我写了一个示例代码是xml数据不显示在HTML页面
<script>
xmlDoc=loadXMLDoc("http://api.openweathermap.org/data/2.5/weather?q=London&mode=xml");
x=xmlDoc.getElementsByTagName('city');
for(i=0;i<x.length;i++)
{
att=x.item(i).attributes.getNamedItem("name");
document.write(att.value + "<br>");
}
</script>
<script >
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",dname,false);
xhttp.send();
return xhttp.responseXML;
}
</script>
我在HTML页面输出应该是“伦敦”。但它什么也没有显示。或者请告诉我的错误。
其实你的代码工作正常。 http://jsfiddle.net/remus/G7eSk/ – brandonscript
@demo_Ashif你在测试什么浏览器?这段代码对我来说看起来很好。 – Rell
thnx小提琴。但我现在应该怎么做?我没有收到数据。 :( –