admin管理员组文章数量:1433500
The javascript I'm using works pletely fine in firefox and ie but has this error when run on chrome and 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 this message but outputs the xmlDoc just fine when I have it set to 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 javascript I'm using works pletely fine in firefox and ie but has this error when run on chrome and 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 this message but outputs the xmlDoc just fine when I have it set to 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
Share
Improve this question
asked Mar 16, 2015 at 21:17
zoomynnzoomynn
31 gold badge1 silver badge3 bronze badges
6
-
Does your
console.log(xmlDoc);
output the expected result? – blex Commented Mar 16, 2015 at 21:21 - yes, in both firefox and chrome – zoomynn Commented Mar 16, 2015 at 21:22
-
getElementsById
is an invalid method, so this should fail in all browsers. Perhaps it fails differently in Chrome and Safari than in IE and Firefox. – Rick Hitchcock Commented Mar 16, 2015 at 21:30 - You're right, I actually copied and pasted the wrong version. At one point, someone suggested I try "byId". I actually originally had getElementsByTagName, which was the source of the original error. Any thoughts ? – zoomynn Commented Mar 16, 2015 at 23:45
-
Does using
getElementsByTagName
resolve your error? – jasonscript Commented Mar 17, 2015 at 2:10
1 Answer
Reset to default 1The problem is that you are trying to get the element by ID and using [0]
, I guess you wanna getElementsByTagName
because that the result is undefined, the code should be:
var changeKey = xmlDoc.getElementsById("t:ItemId").getAttribute("ChangeKey");
Or if "t:ItemId"
is a collection:
var changeKey = xmlDoc.getElementsByTagName("t:ItemId")[0].getAttribute("ChangeKey");
本文标签: javascriptjquery Cannot read property 39getAttribute39 of undefinedStack Overflow
版权声明:本文标题:javascript - jquery Cannot read property 'getAttribute' of undefined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745600652a2665547.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论