1

将浏览器扩展从 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 发送到此函数(缩短)

function getJXONTree(oXMLParent) {
  var vResult = true, nLength = 0, sCollectedTxt = '';
  if (oXMLParent.hasAttributes()) {
    vResult = {};
    [...]

这在 Firefox 中工作得非常好,但在 chrome 中,使用完全相同的代码轮询完全相同的 XML,我得到这个错误:

TypeError: Object #<Document> has no method 'hasAttributes'

我在这里想念什么?

4

1 回答 1

2

Firefox 在这方面更为宽容,但它必须:

xhr.responseXML.documentElement

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

于 2013-07-01T13:53:10.013 回答