Iain Wilson
Iain Wilson

Reputation: 33

Ajax request and text/xml

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?

Upvotes: 2

Views: 306

Answers (2)

Cerebrus
Cerebrus

Reputation: 25775

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;

Upvotes: 1

Iain Wilson
Iain Wilson

Reputation: 33

Fixed it by serializing:

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

Upvotes: 1

Related Questions