#113 enhancement
Steven Pothoven

Cross-browser responseXML functions

Reported by Steven Pothoven | May 19th, 2008 @ 10:01 PM

Most of my Ajax response processing uses the responseXML DOM object. So, each time I get the response, I wrap the responseXML with my own XML wrapper which allows me to traverse the DOM with XPaths. The wrapper extends the DOMDocument by adding functions to is such as getNode, getNodes, getNodeValue, and getNodeValues.

I would like to suggest adding these functions to the responseXML object in the creation of the Ajax.Response such as:

Ajax.Response = Class.create({
    if(readyState == 4) {
      var xml = transport.responseXML;
      // extend xml DOM object here if returned in transport
      xml = Object.isUndefined(xml) ? null : XML(xml);
      this.responseXML  = xml;

FYI, here's an more verbose write up (though I've changed the code structure, and made other changes since then).

I will observe a potential major pitfall to this with my current implementation. For W3C compliant browsers (Firefox, Opera, Safari), the wrapper code as I've implemented it will return an extended version of the original DOM object so anyone using the DOM object currently returned in responseXML won't notice anything if they're using native the DOM functions. However, since IE uses an ActiveX object, it can't be extended the same way, so I added the getDOM function to enable access to the original DOM object. You may have better ways to implement this to circumvent this problem.

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Prototype JavaScript library.

Shared Ticket Bins

People watching this ticket