views:

95

answers:

2

I am requesting and xml file over ajax, the server uses the header text/xml for the data returned. Firefox reads this header and turns the data into an XMLDocument object which means I can't use it with jQuery. How can I get my XML document as plain text?

+1  A: 

The xmlHttp object returned has a responseXML property. This maps to an XmlDocument. If you read the textContent of the childnodes of this document, you will be able to retrieve the plain text response.

For instance:

// Works on FF. For IE, you can read the lastChild.text property.
var responseText = xmlHttp.responseXML.lastChild.textContent;

Alternatively, you can access the responseText property to get the entire response as a string:

// Works on both IE and FF.
var responseText = xmlHttp.responseText;
Cerebrus
+1  A: 

Fixed it by serializing:

var serializer = new XMLSerializer();
var text = serializer.serializeToString(xmldoc);
Iain Wilson