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

标签 javascript reactjs firefox browser axios

我使用 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/

相关文章:

javascript - "JavaScript heap out of memory"传输大文件时

javascript - 将多级 JSON 菜单转换为多级 JSX/HTML 菜单

javascript - 使用 forEach 与 Filelist react setState

javascript - 如何更好地格式化从 api 提取的数据到 Ant 设计表

javascript - 如何使用 offsetX 和 offsetY 在 firefox 浏览器中的 svg 内移动一个圆圈?

javascript: document.write 函数已重新定义,我该如何恢复它

javascript - PushState:如何添加查询字符串而不重定向

javascript - 强制异步调用以同步方式运行

javascript - 检测使用 window.open 打开的窗口的 onload 事件

html - 如果位置延伸到外部,Firefox 会在嵌套 div 时扩大边框