views:

28

answers:

1

I am working on a site server side that has uses XML to get data. The path to the XML I need is something like "/image/user/username/"

I need to get the XML file from that resulting link using something like

 <script type="text/javascript">

imagesByUser('/../image/user/{{ user.username }}/') 

I know that the link is working because I tested it seperately and when I clicked on it, it took me to the correct page with the XML data. However, when I try to parse the data I get an xmlHttp.responseXML is null error on this line

var images= xmlHttp.responseXML.documentElement.getElementsByTagName("image");

I get the file with this

    xmlHttp.open("GET",url,true);

xmlHttp.send();

Also, it works when I use a direct file like imagesByUser('images.xml')

So why wont it work from a page off the server??

A: 

Reading your question from bottom - I got stuck at So why wont it work from a page off the server??

You must specify the correct protocol for AJAX to work. For pages on a hosted server, it must be http:// and for files on the local file system, it must be file:///path/filename.

As far as I know, to work properly with XMLHttpRequest object, you must use the protocol correctly see example at Mozilla Developer Center