The data can be inserted into the database and the JSON also can be generated very well but why is 'Unexpected token < in JSON at position 1' thrown?
The problem has been shown in the picture
signup.ts
signup(){
this.authService.postData(this.userData,'signup').then((result) => {
this.responseData = result;
if(this.responseData.userData){
console.log(this.responseData);
localStorage.setItem('userData', JSON.stringify(this.responseData));
this.navCtrl.push(LoginPage);
}
else{ {swal({
title: "User already exist.Please try again",
})
} }
}, (err) => { ;
// Error log
});
}
You're getting BR tag in your response, and because of that it can't be parsed to JSON, so remove the
> <br />batman2@gmail.comhere
tag from your response.
您可以使用rxjs 映射操作符来验证服务中的JSON响应:
this.http.get(YOUR_URL).map(res => res.json());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.