如何使用 HTML5 Fetch API 修复 RactiveJs 中 OpenWheather API 的不透明响应

How to fix the OpenWheather API's opaque response in RactiveJs with HTML5 Fetch API

这是我们第一次弄脏我们的手Fetch HTML5 API and Ractive JS

我们 this code here 没有抛出任何错误。

注意no-cors header设置为请求参数。

We just need to get the free API data from the Open Weather Map guys.

如何使用 HTML5 Fetch API

修复 RactiveJs 中的不透明响应

您的代码需要更正以下错误

  1. 使用 api.openweathermaps.org 而不是 sample.openweathermaps.org
  2. 使用 GET 而不是 POST
  3. 使用 VALID api 密钥(是的,您可以获得免费密钥)
  4. 正确使用 fetch

fetch('http://api.openweathermap.org/data/2.5/weather?q=London,uk&appid=**valid api key**', {
    method: 'GET',
    redirect: 'follow'
})
.then(response => response.json())
.then(data => console.dir(data));