Hi there, folks.
I've already asked here a question about this issue. The thing is that 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 why does Internet Explorer gets a "null" reference when I parse the XML response (see above). I already have it working on Firefox, Chrome and Opera and it works. It even works on Internet Explorer, when the XML response element does not contain HTML content. Weird? Can anyone help me out with this?
Code snipped of my Javascript object, to make assynchronous AJAX calls to that handler:
if (window.XMLHttpRequest) {
// Mozilla/Safari/IE 7+
http = new window.XMLHttpRequest();
if (http.overrideMimeType)
http.overrideMimeType("text/xml");
}
else {
// IE 5/6
http = new ActiveXObject("Microsoft.XMLHTTP");
}
XML Response returned by the handler (checked via Firebug using Firefox):
<reply>
<message>
<messageId>2</messageId>
<body><![CDATA[I'm sending you this message to invite you to join us!<br/><a href="http://www.whitehouse.gov">White House.gov</a><br/>Thank you for your time.]]></body>
</message>
</reply>
Client-side Javascript function to affect the user-interface with the data returned via AJAX (in this example I've simplified it by simply trying to print out the message id):
function GetMessageContentsCallback(args, resp) {
// Response only contains one "message" element (at the 1st position)
var message = resp.getElementsByTagName('message')[0];
// This alert prints "null" on IE, but works OK on Firefox, Chrome & Opera!
alert("message = " + message );
/* ...and IE then breaks here, with this message:
"Microsoft JScript: 'null' is null or not an object" */
var messageId = message.getElementsByTagName('messageId')[0].firstChild.nodeValue;
alert("messageId = " + messageId);
}
What the hell am I doing wrong here? When this XML reply does not contain HTML content, it works. When it contains HTML content, Internet Explorer doesn't work with my solution... although everybody else (Firefox, Chrome and even Opera) does! Damn! :(