因为我正在使用ionic3并且我无法理解问题所在并且当我尝试创建登录功能时它显示“JSON输入的意外结束”并且在响应端数据也是空白的。
或者它是API连接问题???
我无法解决,有人知道请教我,我会很感激〜
login.ts
login(){
this.authService.postData(this.userData,'login').then((result) => {
this.responseData = result;
if(this.responseData.userData){
console.log(this.responseData);
localStorage.setItem('userData', JSON.stringify(this.responseData)|| "[]");
this.navCtrl.push(IframePage);
}
else{ swal({
title: "Invalid Username or Password",
text: "Please Try Again",
icon: "warning",
}); }
}, (err) => {
// Error log
});
AUTH-service.ts
this.http.post(apiUrl + type, JSON.stringify(credentials),{headers:headers})
.subscribe(res => {
resolve(res.json());
}, (err) => {
reject(err);
});
});
答案 0 :(得分:1)
auth.service.ts
import 'rxjs/add/operator/map';
return this.http.post(apiUrl + type, JSON.stringify(credentials),{headers:headers}).map(res => res.json())
订阅登录功能
login(){
this.authService.postData(this.userData,'login').subscribe((result) => {
this.responseData = result;
if(this.responseData.userData){
console.log(this.responseData);
localStorage.setItem('userData', JSON.stringify(this.responseData)|| "[]");
this.navCtrl.push(IframePage);
}
else{ swal({
title: "Invalid Username or Password",
text: "Please Try Again",
icon: "warning",
}); }
}, (err) => {
// Error log
});