gpt4 book ai didi

javascript - Firefox 出现网络错误,而其他浏览器工作正常(ReactJS 应用程序)

转载 作者:行者123 更新时间:2023-12-01 15:10:09 25 4
gpt4 key购买 nike

我使用 React.js 制作了一个 Web 应用程序,并通过 Axios 调用后端。

但是,Firefox 在等待服务器响应时不断给我一个网络错误。其他浏览器,如 Chrome、Safari、Opera 运行良好。

请求代码:

export function postLoginDetails(username, password, token) {
const url = ENV.host + "/login";

return axios({
method: 'post',
url: url,
withCredentials: true,
headers: {
"X-CSRFToken": token
},
data: {
username: username,
password: password,
},
responseType: 'json'
}).catch(e => console.log(e))
}

这是发生错误的代码: res 未定义。
postLoginDetails(username, password, this.token).then((res) => {
if (res.data.success) {
this.isAuthenticated.set(true)
cb();
} else {
this.error.set(true);
this.errorText = observable('Fehler aufgetreten');
this.name = observable('');
}
this.loginLoading.set(false);
})

Heres the error in Firefox

最佳答案

对于遇到此问题的其他人,我无法谈论飞行前选项的内容,但我知道 Firefox 正在告诉 axios 终止请求。如果您查看处理错误的 axios 部分,您会看到以下注释:

// Handle browser request cancellation (as opposed to a manual cancellation)
所以这是某种浏览器的怪癖。我没有使用按钮来触发请求,而是使用 anchor 标签 <a> .当我将其更改为 <span> 时,它开始工作了反而。为什么,火狐?

关于javascript - Firefox 出现网络错误,而其他浏览器工作正常(ReactJS 应用程序),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49853575/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com