I’ve been working on this way too long now and can’t figure it out. I want to be able to display the current temperature in a city, from the Environment Canada data, on my website. I’ve been through their maze of pages about the maps and api and such, but I can’t find anything basic enough for what I need. (I have been able to get a map with precipitation radar overlaid, which I would have thought would be more complicated than simply getting a temperature, but I digress.)
I found an xml document that contains the data I want, but when I try to fetch it with a script I get CORS error for same origin policy. Unfortunately, I need the data from this specific source (I’ve been able to get the Visual Crossing API to work in the interim). Any help figuring out how to accomplish this task would be much appreciated!
I honestly have no idea how to go about it, when I tried a while ago I just copy/pasted something from online. Now I’m going through the intermediate JS course and just started using the fetch() function, so I thought I’d try again, but I got the familiar CORS error. Right now I have this:
I am looking into this still, but beside the potential CORS issue, you are trying to parse xml with json parsing functions. I know you will need to use other methods to pull the data out of the potential response. For example:
let xml = new window.DOMParser().parseFromString(data, "application/xml");
Hm, yeah I guess I’ll try sending them an email and see if they have some insight, and I’ll play around with the stackoverflow methods too. I’ll update here if I figure something out. Thanks for the replies!
This is very helpful! Thank you, I don’t know how I didn’t come across it. Not sure if it will work exactly how I want but it will be a great solution in the meantime.