我正在尝试将一部分添加到我的应用程序中,用户可以在其中更新他的个人资料信息。但是,当我点击“更新”时,错误代码:422(无法处理的实体)返回。我调查了它,但我不确定它的含义或如何解决它。下面是我的代码:
editUser(e) {
e.preventDefault();
const user = localStorage.getItem('user');
const token = localStorage.getItem('token');
axios.put(`https://myflix-by-jop.herokuapp.com/user/update/${user}`,
{
name: this.state.Name,
username: this.state.Username,
password: this.state.Password,
email: this.state.Email,
birthday: this.state.Birthday
},
{
headers: { Authorization: `Bearer ${token}` }
})
.then((response) => {
this.setState({
name: reposnse.data.Name,
username: response.data.Username,
password: response.data.Password,
email: response.data.Email,
birthday: response.data.Birthday
});
localStorage.setItem('user', this.state.Username);
const data = response.data;
console.log(data);
console.log(this.state.Username);
alert("Profile updated.");
})
.catch(function (error) {
console.log(error);
})
}
setName(value) {
this.state.Name = value;
}
setUsername(value) {
this.state.Username = value;
}
setPassword(value) {
this.state.Password = value;
}
setEmail(value) {
this.state.Email = value;
}
setBirthday(value) {
this.state.Birthday = value;
}
如果您需要我提供更多代码,请告诉我!谢谢!