subscribe()
안에있는 조건에서 값을 설정하려고합니다. 여기에 내가 순간조건 각도 (이온 3)에서 변수 값을 설정
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);
에서 뭘하는지입니다
이 코드는 항상 나에게 내부 undefined
를 제공 내 console.log(statuscode);
을;
이외에도이 페이지는 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
을 보여주고 싶다. 이 일을 할 때 :
TypeError: Cannot read property 'create' of undefined
어떤 아이디어 :
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();
}
);
}
나는이 오류가?
내부의 문을 이동해야합니다;'지정된 상태 코드에 대해. – YVS1102
왜 구독 할 수 없습니까? –
내 업데이트를 확인하십시오. – YVS1102