我正在开发一个具有 React/Spring Boot/MYSQL 堆栈的项目,并且收到错误消息“POST 415: SyntaxError: Unexpected end of input at line 67” 下面是第 67 行,下面是第 67 行是它所属的函数:
}).then(res => res.json())
功能:
handleRegisterSubmit(e, data) {
console.log('submitting')
let stringer = JSON.stringify(data)
console.log(stringer)
// console.log(data)
e.preventDefault()
fetch('/api/register', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
credentials: 'include',
mode: 'no-cors',
body: JSON.stringify(data)
}).then(res => res.json())
.then(res => {
// debugger
console.log(res)
this.setState({
auth: res.auth,
user: res.data.user
})
}).catch(err => console.log(err))
}
我记录了函数中发送的字符串化数据,并能够使用 Postman 中的相同字符串创建帐户。由于它是通过 postman 工作的,所以我认为我将其发布到数据库的方式有问题,但我很难弄清楚是什么。我之前在 React 中使用过同样的函数,并以 Rails/Node w Postgres 作为后端,并且我不确定是否需要对当前项目使用的堆栈做一些不同的事情。如果有人对我如何/应该从这里进一步排除故障有任何建议,我将不胜感激。
预先感谢您的回复!
最佳答案
与我合作的后端开发人员能够弄清楚如何禁用 COR 要求并解决了问题。将尽快标记为已答复。
关于javascript - 能够通过 Postman 创建帐户,从 React 创建问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50431150/