【发布时间】:2017-12-15 07:49:20
【问题描述】:
我正在尝试根据subscribe() 中的条件设置一个值。这是我目前正在做的事情
var statuscode;
this.http.post('http://192.168.3.223:84/fppb/andro_login',this.loginData)
.subscribe(
function(response) {
console.log(response);
if(response)
statuscode = '1';
else
statuscode = '2';
},
function(error) {
statuscode = '3';
}
);
loader.dismiss();
console.log(statuscode);
这段代码总是在我的console.log(statuscode); 中给我undefined;
除此之外,此页面:http://192.168.3.223:84/fppb/andro_login 正在返回 true 或 false。这是确定响应的代码:
if($query->num_rows() > 0)
{
echo json_encode(true);
}else{
echo json_encode(false);
}
我该如何解决这个问题?
对不起,我的英语很差,提前谢谢。
编辑
所以,我想为指定的statuscode 显示alert。这样做时:
signIn(){
let loader = this.ld.create({ content: "Please wait..." });
loader.present();
var headers = {
'Access-Control-Allow-Origin' : '*',
'Access-Control-Allow-Methods' : 'POST'
};
let bodyString = JSON.stringify(this.loginData); // Stringify payload
var statuscode;
this.http.post('http://192.168.3.223:84/fppb/andro_login',this.loginData)
.subscribe(
function(response) {
console.log(response);
if(response)
{
let alert = this.alertCtrl.create({
title: 'Sukses',
subTitle: 'Login Berhasil',
buttons: ['OK']
});
loader.dismiss();
alert.present();
}
else {
let alert = this.alertCtrl.create({
title: 'Gagal',
subTitle: 'Username atau Password salah',
buttons: ['OK']
});
loader.dismiss();
alert.present();
}
},
function(error) {
let alert = this.alertCtrl.create({
title: 'Gagal',
subTitle: 'Username atau Password salah',
buttons: ['OK']
});
loader.dismiss();
alert.present();
}
);
}
我收到此错误:
TypeError: 无法读取未定义的“创建”属性
有什么想法吗?
【问题讨论】: