mongodb Uncaught(in promise)SyntaxError:意外的标记“|”,“〈!DOCTYPE”...不是有效的JSON错误

e7arh2l6  于 2023-04-20  发布在  Go
关注(0)|答案(1)|浏览(252)

我的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错误

zvms9eto

zvms9eto1#

当你的数据不是JSON格式时会发生这个错误。对我来说,你上面的代码看起来很好,请检查你的后端返回的是什么。

相关问题