2016-10-12 69 views
-4
export class LoginPage { 

login:{username ?: string,password ?: string} = {}; 提交= false;如何從離子2應用程序的php服務器獲取數據

構造(公共navCtrl:NavController,公共用戶數據:的UserData,私人菜單:MenuController){}

onLogin(形式){ this.submitted = TRUE;

if (form.valid) { 
    this.userData.login(this.login.username); 
    this.navCtrl.setRoot(Page1); 
} 

}

回答

0

你必須異步調用你的PHP後臺通過AJAX:

return $http.get("https://yourbackend.com/api/your_call") 
    .then(function(response){ 
     /* Here you can process the backend response */ 
    }); 
0

當我打電話PHP服務器,服務器使用JSON數據對象迴應我,我需要導航如果狀態爲真,則轉到頁面。

login(){ 

let headers = new Headers(); 
    headers.append('Content-Type', 'application/json'); 

let alert = this.alert.create({ 
      title: 'Warning', 
      subTitle: 'Wrong Username or Password! Please Try Again !', 
      buttons: ['OK'] 
      }); 
let loader = this.loading.create({ 
      content: "Checking ! Please wait...", 
      duration: 1000 
     }); 

let email = this.data.email; 

let password = this.data.password; 
let data = JSON.stringify({email, password}); 
let link = "http://"link""; 


    this.http.post(link, data, {headers: headers}) 
     .subscribe(res => { 
     this.navCtrl.setRoot(Page1); 
     loader.present(); 
     console.log(res.json()); 
     }, (err) => { 
     console.log(err); 
     alert.present(); 
     }); 

}}

相關問題