【发布时间】:2015-03-16 21:17:29
【问题描述】:
我使用的 javascript 在 firefox 和 ie 中运行良好,但在 chrome 和 safari 上运行时出现此错误。我不完全确定它为什么会失败。
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");
控制台显示此消息,但当我将其设置为 console.log() 时输出 xmlDoc 就好了
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
【问题讨论】:
-
你的
console.log(xmlDoc);是否输出了预期的结果? -
是的,在 Firefox 和 chrome 中都可以
-
getElementsById是无效的方法,因此在所有浏览器中都应该失败。也许它在 Chrome 和 Safari 中的失败与在 IE 和 Firefox 中不同。 -
你说得对,我实际上复制并粘贴了错误的版本。有一次,有人建议我尝试“byId”。我实际上最初有 getElementsByTagName,这是原始错误的来源。有什么想法吗?
-
使用
getElementsByTagName可以解决您的错误吗?
标签: javascript jquery soap exchangewebservices