我的register.js文件
const data = await fetch(“/register”,{ method:“POST”,headers:{“Content-Type”:“application/json”},body:JSON.stringify({ fname,email,password,cpassword })});
const res = await data.json();
// console.log(res.status);
if (res.status === 201) {
toast.success("Registration Successfully done 😃!", {
position: "top-center"
});
setInpval({ ...inpval, fname: "", email: "", password: "", cpassword: "" });
}
}
}
我试图在我的数据库中注册一个用户,但当我这样做,我得到了这个uncaught无效的JSON错误
1条答案
按热度按时间zvms9eto1#
当你的数据不是JSON格式时会发生这个错误。对我来说,你上面的代码看起来很好,请检查你的后端返回的是什么。