View Full Version : fetch xml using ajax

03-08-2011, 09:11 AM
I am sending a getCapabilities- request "http://atlas.gc.ca/cgi-bin/atlaswms_en?VERSION=1.1.1&REQUEST=Getcapabilities&SERVICE=wms" that results in a xml-file, I want to parse this file to get the layers in a rollist.

The problem is that i don't know hot to get the requested xml-file, I don't know how or where in the code to put the url. I am using httpXMLrequest but i do not get it to work..
I am using javascript
please help me!


03-08-2011, 02:59 PM
If your httpXMLrequest originates from another domain (not atlas.gc.ca), this violates the same origin policy and will not work. You would have to fetch it on the server side and pass it to your Javascript from there. If the request does originate from atlas.gc.ca, you would have to post some code, so we can see why it's not working.

03-09-2011, 03:49 PM
Okey, I'm setting up a website from my own pc: in the javascript I would like a function that via a httpXMLrequest saves the getcapabilties xml, so I can parse it and use the values in different fields in the website. I don't know where to put the URL and which url to use. can tou help me with the javascript and give me an example of code that would save the xml from atlas.gc.ca?

03-09-2011, 04:31 PM
Well, you can't do that. It violates the same-origin policy. Also, you can't use Javascript to save files. But you can fetch the file on the server side (i.e. with PHP, using simplexml_load_file or something) and use it however you like; either directly use the data to build the HTML, or pass it off to Javascript as JSON.

Also, what's
I don't know where to put the URL and which url to use. supposed to mean? How would I know which URL you need to use for whatever you are doing? What's wrong with the one in your original post?

03-09-2011, 08:22 PM
I ment the Url in the first post, and if I should use the whole file, never mind, I also saw I was a little bit unclear there. Thanks for your help and I will try to solve it with your tips.