开发者

Get XML page from path name

开发者 https://www.devze.com 2023-01-20 21:29 出处:网络
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 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开发者_如何学C 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??


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

0

精彩评论

暂无评论...
验证码 换一张
取 消