我正尝试在jQuery中使用ajax请求读取XML。下面是代码,它在IE浏览器工作正常,但是当我在Chrome运行此我面对这个错误未捕获TypeError:无法调用未定义的方法'hasChildNodes'
Uncaught TypeError: Cannot call method 'hasChildNodes' of undefined
$.ajax({
type: "GET",
url: "tree1.xml",
dataType:"xml",
success: function(xml){
root=xml.documentElement;
childs=root.childNodes;
for(var i=0;i<childs.length;i++){
z=childs[i].childNodes;
adChilds(z,childs,oNode);
function adChilds(a,b,c){
if(a[i].hasChildNodes()){
adNode(b[i].nodeName,c);
var oNode_ch=oNode1;
for(var j=0;j<a.length;j++){
child1=a[j].childNodes;
adNode(child1[0].nodeValue,oNode_ch);
}
}
else{adNode(a[0].nodeValue,oNode);}
}
}
错误是在该行指出。
如果(A [1] .hasChildNodes()){
任何人都可以给我建议我该怎么错在何处。
在此先感谢!
嗯......看起来'a [i]'是'undefined',所以请使用'console.log()'检查变量的值以开始调试。 –