从JS中的XML在线文件中获取数据

时间:2019-07-07 18:38:12

标签: javascript xml fetch

我想从仅提供xml格式的站点下载天气数据。

我已经尝试了许多方法,但是仍然无法正常工作。我也尝试过XMLHttpRequest,效果是一样的。

   fetch(
        "https://www.yr.no/place/Poland/Lesser_Poland/Rysy/forecast_hour_by_hour.xml",
        {
          mode: "no-cors",
          headers: {
            "Access-Control-Allow-Origin": "*"
          }
        }
      )
        .then(res => res.text())
        .then(str => new window.DOMParser().parseFromString(str, "text/xml"))
        .then(res => console.log("Yr.no:", res));

我的“ res”为空。

0 个答案:

没有答案