Nightmare! This took me ages to solve, but was actually quite easy in the end.
I thought it'd be a great idea to have "live" validation on a registration page, that'd check the database to see if a username had already been chosen.
First I created a ColdFusion Component (CFC) as a web service which checks the user input against usernames in the database and returns a boolean true/false. The CFC returns a WDDX formatted XML packet containing the boolean value.
Assuming you have a response handler like the AJAX tutorial here: http://developer.mozilla.org/en/docs/AJAX, all you need to do is use http_request.responseXML to receive the XML content and then use the XML DOM properties and methods to extract the data.
This works fine in Mozilla browsers like FireFox / Safari, but not in IE, which produces an 'Object Expected' error.
This is because IE expects all XML responses to have: Content-Type: 'text/xml' in the response header. However, ColdFusion broadcasts the WDDX packet as 'text/html', and therefore using responseXML in the javascript handler will not work, as IE doesn't acknowledge this as XML data.
The simple way to fix this is to create an XML DOM object in the Javascript response handler and use the responseText property, like so:
if(window.ActiveXObject){ // If IE Windows
var XMLdoc = new ActiveXObject("Microsoft.XMLDOM");
XMLdoc.loadXML(http_request.responseText);
} else {
var XMLdoc = http_request.responseXML;
}
14 comments:
Dan, thank you very much for your article. I had the problem with parsing XML data retrieved, and didn't think that there could be a bug at IE on this. Thanks again! Best, Sergei.
thanks - this helped out a bunch!
Thank you sooooo much!! It works great!
Cheers,
Su
OMG..... thank you... .that took forever... friggin IE
You have no idea how long I was struggling with this. So glad I happened across your article. Thanks!
thank you very much!
And another big thanks! This was really slowing me down.
Thank you very much! This solution is great!
OMG, thank you!
Thanks a lot for your post!
Greets from Germany
Thank you so much!!!
That worked perfectly !!!!
Greetings from Brazil.
Thanks you helped me a lot, thanks man.
This is very great thank a lots
Awesome! Thank you very much.
Post a Comment