Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript XML到JSON在firefox中工作,但在chrome中产生TypeError_Javascript_Xml_Json_Google Chrome Extension_Firefox Addon - Fatal编程技术网

Javascript XML到JSON在firefox中工作,但在chrome中产生TypeError

Javascript XML到JSON在firefox中工作,但在chrome中产生TypeError,javascript,xml,json,google-chrome-extension,firefox-addon,Javascript,Xml,Json,Google Chrome Extension,Firefox Addon,我正在将浏览器扩展从FF移植到chrome。我有一个XMLHttpRequest,它可以正常工作: var xhrdata = new XMLHttpRequest(), xhrdata.onreadystatechange = function () { if (xhrdata.readyState === 4) { if (xhrdata.status === 200) { get

我正在将浏览器扩展从FF移植到chrome。我有一个XMLHttpRequest,它可以正常工作:

var xhrdata = new XMLHttpRequest(),

xhrdata.onreadystatechange = function () {               
    if (xhrdata.readyState === 4) {
        if (xhrdata.status === 200) {                
            getJXONTree(xhrdata.responseXML);                
        }
    }
};
xhrdata.open("GET", "mydomain.com/my.xml", true);
xhrdata.responseType = "document";
xhrdata.send();
这会将.responseXML发送到此函数(缩短)

这在firefox中非常有效,但在chrome中,使用完全相同的代码轮询完全相同的XML时,我得到以下错误:

TypeError: Object #<Document> has no method 'hasAttributes'
TypeError:对象#没有方法“hasAttributes”

我在这里遗漏了什么?

Firefox在这方面更为宽松,但必须做到:

xhr.responseXML.documentElement

因为文档没有任何属性。谢谢@robW

确保使用正确的内容类型文档不能有任何属性。Firefox在这一点上是错误的。您需要在节点上使用
hasAttributes
,例如通过使用
getJXONTree(xhrdata.responseXML.documentElement)@robW jep没错,谢谢!
xhr.responseXML.documentElement