DennisBB

web development that roxx
Get A Free Quote
  • Home
  • Portfolio
  • Services
  • Contact
  • About
< Ruby 1.9.1 and Rails
Say Bye to GeoCities >

Ajax in real XHTML

I’ve been workin today on Live Search for this web site. It uses Ajax and since this site is made in real XHTML, JavaScript works in xml mode.

When you work with JavaScript in real XHTML sites sometimes things are different than what they used to be. For example, you make an Ajax call and got transport.responseXML object. This is what you do to add that xml to your code.

var content = $('content')
var res_xml = document.importNode(transport.responseXML.documentElement, true)
content.parentNode.replaceChild(res_xml, content)

You can’t just take plain transport.responseXML object and use replaceChild or appendChild methods on it. You need to call importNode or adoptNode first, to import it to the current document, only after that you can use replaceChild or appendChild.

It took me 2 hours to figure that out, because Safari doesn’t show any error message when you don’t use importNode, it just doesn’t work. And in Firefox it works, but without any error message or a warning, which makes it very difficult to find the error.

Tags: ajax

This entry was posted on Monday, April 20, 2009 at 10:37 am and is filed under Programming. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply
Click here to cancel reply.

Terms of Use Privacy Policy
Copyright © 2010 DennisBB