后端: spring启动和一切都在后端工作,但是当我尝试登录react时,我在开发工具Chrome in Network中看到登录是正常的,并且是status=200,但是当我尝试提取响应和jwt时,我看到这个错误: SyntaxError:意外的JSON输入结束
这是我的代码
async sbmit(e){
e.preventDefault()
//console.log(this.state)
await fetch('http://localhost:8080/login', {
method: 'POST',
body: JSON.stringify(this.state)
}).then(res=>console.log(res.json()))
}发布于 2021-09-08 00:20:08
res.json()返回一个promise。您需要在另一个.then处理程序中包含您的console.log,它将正常工作。您也可能遇到cors问题,但如果是这种情况,您应该会在控制台中看到一条消息。因为本地主机通常受到保护,不受其他站点向其发出请求。
https://stackoverflow.com/questions/69095632
复制相似问题