javascript - jquery Cannot read property 'getAttribute' of undefined -
the javascript i'm using works fine in firefox , ie has error when run on chrome , safari. i'm not entirely sure why it's failing.
var response = asyncresult.value; if (window.domparser) { var parser = new domparser(); xmldoc = parser.parsefromstring(response, "text/xml"); } else { xmldoc = new activexobject("microsoft.xmldom"); xmldoc.async = false; xmldoc.loadxml(response); } console.log(xmldoc); var changekey = xmldoc.getelementsbyid("t:itemid")[0].getattribute("changekey");
the console shows message outputs xmldoc fine when have set console.log()
uncaught typeerror: cannot read property 'getattribute' of undefined r.js soaptogetitemdatacallback r.js r.onreadystatechange outlookwebapp-15.js:21 $h.ewsrequest.$1x_1 outlookwebapp-15.js:21 (anonymous function) outlookwebapp-15.js:21
the problem try element id , using [0]
, guess wanna getelementsbytagname
because result undefined, should be:
var changekey = xmldoc.getelementsbyid("t:itemid").getattribute("changekey");
or if "t:itemid"
collection:
var changekey = xmldoc.getelementsbytagname("t:itemid")[0].getattribute("changekey");
Comments
Post a Comment