【发布时间】:2022-01-02 00:26:09
【问题描述】:
我正在尝试通过 Axios 发出 API 请求,但收到此错误。
Error: Network Error
at e.exports (createError.js:16)
at XMLHttpRequest.g.onerror (xhr.js:117)
代码如下:
async function getData() {
await axios
.get(
"api.openweathermap.org/data/2.5/weather?q={city name}&appid={api key}"
)
.then(function (data) {
console.log(data);
})
.catch(function (err) {
console.log(err);
});
}
我该如何解决这个问题?
谢谢
【问题讨论】:
-
需要更多细节。您遇到的网络错误是什么?例如403? 404?别的东西?它是否带有错误消息?
-
我也得到了这个:CORS 策略已阻止从源“null”访问 XMLHttpRequest:跨源请求仅支持协议方案:http、data、chrome、chrome-extension、chrome - 不受信任,https。
标签: javascript api axios weather openweathermap