2017-02-10 53 views
1

这是我们第一次用Fetch HTML5 APIRactive JS弄脏我们的手。如何使用HTML5抓取API修复RoughJs中OpenWheather API的不透明响应

我们this code here这是不会引发任何错误。

请注意将 no-cors标头设置为请求参数。

我们只需要从Open Weather Map guys获得免费的API数据。

如何解决在RactiveJs与HTML5是不透明的响应提取API

+0

'注意无CORS标头设置为请求parameter.' - 这将确保您的代码将无法访问任何回应,是你想要什么? –

+0

@JaromandaX不需要先生,我们需要访问响应。我添加它来抑制错误:( – xameeramir

+0

抑制cors错误不会绕过cors!看起来这个API不会发出任何cors头文件,所以你将无法通过浏览器直接访问该API –

回答

1

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

  1. 使用api.openweathermaps.orgsample.openweathermaps.org
  2. 使用GETPOST
  3. 使用VALID api键(是的,你可以得到一个免费的关键)
  4. 使用取正确

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));