Search code examples
javascriptxmlprototypejs

How do I get an XML file as XML (and not a string) with Ajax in Prototype.js?


This code is from Prototype.js. I've looked at probably 20 different tutorials, and I can't figure out why this is not working. The response I get is null.

new Ajax.Request(/path/to / xml / file.xml, {
   method: "get",
   contentType: "application/xml",
   onSuccess: function(transport) {
      alert(transport.responseXML);
   }
});

If I change the responseXML to responseText, then it alerts to me the XML file as a string. This is not a PHP page serving up XML, but an actual XML file, so I know it is not the response headers.


Solution

  • If transport.responseXML is null but you have a value for transport.responseText then I believe it's because it's not a valid XML file.

    Edit: I just noticed that in our code here whenever we request an XML file we set the content type to 'text/xml'. I have no idea if that makes a difference or not.