小编Zee*_*der的帖子

VM1661:1 未捕获(承诺中)语法错误:JSON 中位置 0 处出现意外标记

大家好,我的网站出现错误很长时间了,我在整个互联网上搜索了答案,但没有找到任何解决方案,这是我的onsubmit代码

onSubmit = () => {
    fetch("http://localhost:2000/signin", {
      method: "post",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        email: this.state.signinEmail,
        password: this.state.signinPassword,
      }),
    })
      .then((response) => response.json())
      .then(console.log(this.state.signinEmail, this.state.signinPassword))
      .then((data) => console.log(data));
  };
Run Code Online (Sandbox Code Playgroud)

我还检查了网络选项卡的响应,它显示成功,但收到此错误不知道如何消除它。我还检查了 Stackoverflow 的解决方案,它写了Accept:application/json但仍然不起作用,但它给了我“错误的请求”错误后端代码是:

app.post("/signin", (req, res) => {
  if (
    req.body.email === database.users[0].email &&
    req.body.password === database.users[0].password
  ) {
    res.send("success");
  } else {
    res.status(400).json("error logging in");
  }
});
 
Run Code Online (Sandbox Code Playgroud)

我还通过Postman对其进行了测试,它可以成功运行,没有错误。这是 json 服务器。 在此输入图像描述

javascript express reactjs

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

express ×1

javascript ×1

reactjs ×1