我真的很感激得到你的幫助,因爲我似乎無法檢測和解決我在使用我正在開發的網站上的AJAX功能所遇到的問題。AJAX XML回覆節點值迭代
我有一個webform
,它對處理程序(.ashx
)進行異步調用,該處理程序提供XML響應,稍後由將其內容放入用戶界面的Javascript客戶端函數進行處理。
我附上我的處理程序生成的響應的一個例子,我想知道什麼是我能得到的所有<body>
元素innerHTML
(與文本和子節點)的內容將其追加到<span>
元素在用戶界面上。任何人都可以幫我解決這個問題嗎? (通過螢火蟲選中)由處理程序返回
XML響應:
<message>
<content>
<messageId>2</messageId>
<from>Barack Obama</from>
<fromMail>[email protected]</fromMail>
<subject>Yes, we can... get World Peace</subject>
<body>Hello, dear citizen. I'm sending you this message to invite you to join us! <a href="http://www.whitehouse.gov">Test link</a> Thank you for your time.</body>
</content>
</message>
客戶端JavaScript功能以影響用戶界面innerHTML
屬性與數據經由AJAX返回:
function GetMessageContentsCallback(args, resp) {
//XML Parser
try {
//Internet Explorer
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = "false";
xmlDoc.loadXML(resp);
}
catch (e) {
parser = new DOMParser();
xmlDoc = parser.parseFromString(resp, "text/xml");
}
var msgReply = xmlDoc.getElementsByTagName('message')[0];
var ajaxRespondeBodyInnerHTML = msgReply.getElementsByTagName(body)[0].firstChild.nodeValue;
//this currently only delivers inner text content, without the <a href... bit and subsequent text
document.getElementById("bodySpan").innerHTML = ajaxRespondeBodyInnerHTML;
}
謝謝你的回覆。但是,您的解決方案似乎並沒有達到我想要的效果,因爲它不顯示「" element of my XML AJAX response, not only the "" node value. – XpiritO 2009-08-19 16:04:12
See my edit for the solution to your answer. – 2009-08-20 19:17:47
Thanks again for your reply, but your solution doesn't seem to accomplish what I want, as I would like to display ALL node and child nodes content on the placeholder. In the end I would like to have this: placeholder.innerHTML = "Hello, dear citizen. I'm sending you this message to invite you to join us! Test link謝謝您的時間。」 感謝您的幫助;) – XpiritO 2009-08-24 13:37:33