views:

432

answers:

1

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.

Edit: You are indeed correct -- I did not close off one of my XML nodes, and it was therefore not valid, which gave the null -- thanks!

+3  A: 

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.

17 of 26