0

Im not an experienced with XML but trying to create a website and need to use some weather data from a norwegian weather services (yr.no) specific this url(https://www.yr.no/sted/Norge/Akershus/B%C3%A6rum/Kols%C3%A5s/varsel.xml)

I have tried using this code under, but having a problem having a problem.. where can i go from here?

fetch('https://www.yr.no/sted/Norge/Akershus/Bærum/Kolsås/varsel.xml', {
    mode: 'no-cors'
})
.then(function(resp) {
  return resp.text();
})
.then(function(data) {
  let parser = new DOMParser(),
      xmlDOc = parser.parseFromString(data, '/sted/Norge/Akershus/Bærum/Kolsås/varsel.xml'
    );
    console.log(xmlDOc);
});
Vetlesen
  • 3
  • 4

1 Answers1

0

mode: 'no-cors' means "I am not doing anything that needs CORS permission, don't ask for it".

resp.text(); requires CORS permission when dealing with cross-origin requests.

So don't say mode: 'no-cors'.

(If the URL does not come with CORS permission, then you'll need to look at changing that or using a proxy. Further reading: XMLHttpRequest cannot load XXX No 'Access-Control-Allow-Origin' header)

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • I didnt need the 'no-cors' because of the 'access-controll-allow-origin' problem. Could I use something else than resp.text();? – Vetlesen Dec 13 '19 at 13:43
  • @Vetlesen — No. If you want to read the content, you need CORS permission (or one of the work arounds described in the answer to the linked question). – Quentin Dec 13 '19 at 13:49