user2420172
user2420172

Reputation: 47

XML to JSON works in firefox but produces TypeError in chrome

Im porting a browser extension from FF to chrome. I have this XMLHttpRequest, which works fine:

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();

This send the .responseXML over to this function (shortened)

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

This works absolutely fine in firefox, but in chrome, polling the exact same XML with the exact same code, I get this error:

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

What am I missing here?

Upvotes: 1

Views: 256

Answers (1)

user2420172
user2420172

Reputation: 47

Firefox is more lenient when it comes to this, but it has to be:

xhr.responseXML.documentElement

since documents dont have any attributes. thanks @robW

Upvotes: 2

Related Questions