这是我们第一次用Fetch HTML5 API和Ractive JS弄脏双手。
我们的this code here不会引发任何错误。
注意no-cors
标头设置为请求参数。
我们只需要从Open Weather Map guys获取免费的API数据。
如何使用HTML5 Fetch API修复RactiveJs中的不透明响应
最佳答案
您的代码需要更正以下错误
使用api.openweathermaps.org
而不sample.openweathermaps.org
使用GET
而不POST
使用有效的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));
关于javascript - 如何使用HTML5 Fetch API在RactiveJs中修复OpenWheather API的不透明响应,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42151153/