收到错误:意外的令牌'<', "<!doctype "... is not valid JSON

问题描述 投票:0回答:1

我有我的投资组合网站,并且正在将博客集成到我的投资组合中,事情位于本地主机上,但在部署控制台显示以下错误后
Blog.js:85 获取博客时出错:意外的标记 '<', "

输入图像描述这里是控制台错误的屏幕截图

以下是从后端获取博客的代码

useEffect(() => {
    const fetchBlogs = async () => {
      try {
        const url = `${host}/blog/blogs`;
        const response = await fetch(url, {
          method: "GET",
          headers: {
            "Content-Type": "application/json",
            "authtoken": localStorage.getItem("token")
          },
        });
        const allblogs = await response.json();
        setBlogs(allblogs);
        setLoading(false);
        extractUniqueTags(allblogs);
      } catch (error) {
        console.error('Error fetching blogs:', error.message);
        setLoading(false);
      }
    };

    fetchBlogs();
    // eslint-disable-next-line
  }, []);

我尝试使用 bodyparser 解决错误,但没有成功,请帮助我解决错误

express syntax-error mern unexpected-token
1个回答
0
投票

您期待 JSON 响应,但没有得到。确保在后端使用 res.json({ "Your data" }),而不是 res.send("Your data")

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.