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

Question :

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

Answer :

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.

Read More  Best implementation for Key Value Pair Data Structure?

,

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.

That’s the answer How do I get an XML file as XML (and not a string) with Ajax in Prototype.js?, Hope this helps those looking for an answer. Then we suggest to do a search for the next question and find the answer only on our site.

Read More  How can I empty the recycle bin for all users from a Windows service application in c#

Disclaimer :

The answers provided above are only to be used to guide the learning process. The questions above are open-ended questions, meaning that many answers are not fixed as above. I hope this article can be useful, Thank you