大家好,我的网站出现错误很长时间了,我在整个互联网上搜索了答案,但没有找到任何解决方案,这是我的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)