reactjs - 获取 SyntaxError: Unexpected token while Running react app
问题描述
console.log
运行反应应用程序时出现错误
这是我的应用程序useEffect:
useEffect(() => {
const fetchData = async () => {
const result = await fetch(`/api/foodies/${name}`);
const body = await result.json();
console.log(body);
setFoodieInfo(body);
};
fetchData();
}, [name]);
我的错误是:uncaught (in promise) syntaxerror: unexpected token < in json at position 0
如何解决这个问题?
解决方案
result
返回 html 而不是 json。run console.log(result.text())
,很可能会有错误的描述。
推荐阅读
- variables - 地形变量
- c# - 在模型中存储函数
- java - Agora.io 视频聊天创建活动
- java - okHttp 3.x 身份验证器没有被调用
- html - 我的按钮在当前页面下方加载一个页面
- c# - 我可以将奥尔良用于过程中的演员/谷物吗?
- django-models - 在 Django Filter 和 Wagtail 中使用 ModelChoiceFilter 时如何防止重复
- reactjs - 如何使用 jenkins 的 build_number 变量作为 reactjs docker 映像的标签?
- azure-devops - 需要 CI CD 组件信息
- reactjs - 为什么访问 id 在 if 和 else 上的工作方式不同?