如何使用HTML5抓取API修复RoughJs中OpenWheather API的不透明响应
问题描述:
这是我们第一次用Fetch HTML5 API和Ractive JS弄脏我们的手。如何使用HTML5抓取API修复RoughJs中OpenWheather API的不透明响应
我们this code here这是不会引发任何错误。
请注意将
no-cors
标头设置为请求参数。
我们只需要从Open Weather Map guys获得免费的API数据。
如何解决在RactiveJs与HTML5是不透明的响应提取API
答
你的代码需要更正以下错误
- 使用
api.openweathermaps.org
不sample.openweathermaps.org
- 使用
GET
不POST
- 使用VALID api键(是的,你可以得到一个免费的关键)
- 使用取正确
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));
'注意无CORS标头设置为请求parameter.' - 这将确保您的代码将无法访问任何回应,是你想要什么? –
@JaromandaX不需要先生,我们需要访问响应。我添加它来抑制错误:( – xameeramir
抑制cors错误不会绕过cors!看起来这个API不会发出任何cors头文件,所以你将无法通过浏览器直接访问该API –