Firefox出现网络错误,而其他浏览器运行良好(ReactJS App)

Dan*_*jic 7 javascript browser firefox reactjs axios

我使用React.js创建了一个Web应用程序,而Im通过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))
}
Run Code Online (Sandbox Code Playgroud)

以下是发生错误的代码: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);
            })
Run Code Online (Sandbox Code Playgroud)

继承人在Firefox中的错误

小智 2

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

// Handle browser request cancellation (as opposed to a manual cancellation)
Run Code Online (Sandbox Code Playgroud)

所以这是某种浏览器的怪癖。我没有使用按钮来触发请求,而是使用锚标记<a>。当我将其更改为 a 时,它开始工作<span>。为什么,火狐?