谁能告诉我为什么我无法从 XML 文档中获取元素?当我按下我在正文部分实现的 et Title 按钮时,它不会打印任何内容。这是我的代码:
function MyF () {
var xmlhttp;
var txt,x,i=0;
var xx;
if (window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}
else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.send();
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
x = xmlhttp.responseXML.documentElement.getElementsByTagName("CD");
xx = x[i].getElementsByTagName("TITLE");
document.getElementById("test").innerHTML=xx;
}
}
xmlhttp.open("GET","cd_catalog.xml",true);
}
最佳答案
xmlhttp.responseXML.documentElement
是您烦恼的问题。只需使用 xmlhttp.responseXML.getElementsByTagName 就可以了。
关于javascript - Ajax 响应 xml 页面获取标题元素不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27550319/