【发布时间】:2018-09-27 21:50:37
【问题描述】:
我正在尝试从天气 api 获取一些天气信息。当我在 Chrome 的控制台中加载此获取代码时,我收到 404 错误。
const getWeather = () => {
return fetch('api.openweathermap.org/data/2.5/weather?
q=London&appid=' + apiKey)
.then(response => response.json())
.then(weather => console.log(JSON.stringify(weather)))
}
getWeather();
它还在我要获取的网址之前显示“http://127.0.0.1:5500/”。什么可能导致添加此内容以及如何使此获取请求正常运行?我希望任何人都可以提供任何帮助。
【问题讨论】:
-
可以在网址中添加
http://吗? -
您的 API 密钥有效吗?
-
这是“http://”的东西。我只是从 Open Weather Map 复制了 url,并没有想到 http 不存在。谢谢马克!
标签: javascript api get fetch