[英]Parse xml data in javascript
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);
}
不,您不需要轉換響應,因為您可以直接通過responseXML
屬性獲取xmlDoc
。
例:
xmlDoc = xmlResponse.responseXML; // you'll probably need to change it because I don't know what is value of xmlResponse in your case
id = xmlDoc.getElementsByTagName("id")[0].childNodes[0].nodeValue;
//and so on...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.