0
- 我是否需要将响应从servlet(xml)转换为xmlDoc,以便解析和检索某些值的 ?
- 如果是,那么下面的代码是否正确?
console.log(id);
打印一个函数,因此引发TypeError。如果没有,那该怎么办呢?
function xmlParser(xmlResponse) {
if (window.DOMParser) {
parser = new DOMParser();
console.log(xmlResponse);
xmlDoc = parser.parseFromString(xmlResponse, "text/xml");
console.log(xmlDoc);
}
id = xmlDoc.getElementsByTagName("id")[0].childNodes[0].nodeValue;
console.log(id);
key = xmlDoc.getElementsByTagName("passkey")[0].childNodes[0].nodeValue;
console.log(key);
return format(id, key);
}
的内容类型从服务器的响应必须是“text/xml”的或你的responseXML属性将是无效的。 – Ben 2013-05-05 10:39:46
我删除了转换代码。我从servlet发送xml。但仍然得到'Uncaught TypeError:无法读取属性'childNodes'undefined' – John 2013-05-05 11:10:34
我的坏...它解决了 – John 2013-05-05 11:20:53