Javascript XML到JSON在firefox中工作,但在chrome中产生TypeError
我正在将浏览器扩展从FF移植到chrome。我有一个XMLHttpRequest,它可以正常工作: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
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