Hi there, guys.
I would really appreciate to get your help on this, as I can't seem to detect and solve the problem I'm having with an AJAX functionality on a site that I'm currently developing.
I have a webform that makes an asynchronous call to a handler (.ashx) that delivers a XML
response that is later processed by a Javascript client-side function that places it's contents into the user-interface.
I'm attaching an example of the
response generated by my handler, and what I would like to know is how can I get all the <body> element innerHTML (with the text and child nodes) contents to append it to a <span> element on the user-interface. Can anyone help me out with this?
XML
Response returned by the handler (checked via Firebug):
<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>
Client-side Javascript function to affect the user-interface innerHTML property with the data returned via 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;
}