【问题标题】:500 Error and Unexpected token < in JSON at position 0 when deployed MERN on Heroku在 Heroku 上部署 MERN 时,位置 0 处的 JSON 中出现 500 错误和意外令牌 <
【发布时间】:2021-10-18 19:22:02
【问题描述】:

我已经在 Heroku 上部署了我的第一个 MERN 应用程序。尝试登录我的应用程序时,我在位置 0 处收到 500 (Internal Server Error) 和 SyntaxError: Unexpected token

const onSubmit = (e) => {
    e.preventDefault();
    fetch("/api/users/login", {
      method: "POST",
      headers: {
        "Content-Type": "application/json"
      },
      body: JSON.stringify({
        email,
        password
      })
    })
      .then((response) => response.json())
      .then((data) => {
        setForm({ email: "", password: "" });

        localStorage.setItem("jwt", data.token);
        dispatch(set_loggedUser(data.user));
        dispatch(set_islogged());

        history.push("/");
      })
      .catch((err) => console.log(err));
  };

【问题讨论】:

    标签: node.js reactjs express heroku mern


    【解决方案1】:

    检查response。至少,您可以在此处记录响应。

    .then(
        (response) => 
        {
            console.log(response)
            return response.json()
        })
    

    【讨论】:

      猜你喜欢
      • 2021-07-20
      • 2018-04-20
      • 2022-07-11
      • 1970-01-01
      • 2020-04-23
      • 2020-11-20
      • 2018-08-01
      • 2018-10-23
      • 1970-01-01
      相关资源
      最近更新 更多