Ionic2 离子2中的登录验证
我试图在我的应用程序中做登录功能,但我得到了这个 错误“响应状态为0 URL:Null”,我希望有人能帮助我解决此问题 授权服务Ionic2 离子2中的登录验证,ionic2,Ionic2,我试图在我的应用程序中做登录功能,但我得到了这个 错误“响应状态为0 URL:Null”,我希望有人能帮助我解决此问题 授权服务 let apiUrl='http://localhost:8888/PeopleService/auth/lognin.php login(credentials) { return new Promise((resolve, reject) => { let headers = new Headers(); h
let apiUrl='http://localhost:8888/PeopleService/auth/lognin.php
login(credentials) {
return new Promise((resolve, reject) => {
let headers = new Headers();
headers.append('Content-Type', 'application/json');
this.http.post(apiUrl+'login', JSON.stringify(credentials), {headers: headers})
.subscribe(res => {
resolve(res.json());
}, (err) => {
reject(err);
});
});
}
login.ts
loginData = { PHONENUM:'', PASSWORD:'' };
doLogin() {
this.showLoader();
this.authService.login(this.loginData).then((result) => {
this.loading.dismiss();
this.data = result;
this.navCtrl.setRoot(HomePage);
}, (err) => {
this.loading.dismiss();
this.presentToast(err);
});
}
showLoader(){
this.loading = this.loadingCtrl.create({
content: 'Authenticating...'
});
this.loading.present();
}
登录html
<ion-content padding>
<h2>Please, Login</h2>
<form (submit)="doLogin()" name="login" id="login">
<ion-item>
<ion-label stacked>Username</ion-label>
<ion-input [(ngModel)]="loginData.PHONENUM" name="PHONENUM" type="text" placeholder="Username" ></ion-input>
</ion-item>
<ion-item>
<ion-label stacked>Password</ion-label>
<ion-input [(ngModel)]="loginData.PASSWORD" name="PASSWORD" type="password" placeholder="Password"></ion-input>
</ion-item>
<button ion-button block type="submit">
Login
</button>
</form>
</ion-content>
看起来url没有解析。您正在发布到
http://localhost:8888/PeopleService/auth/lognin.phplogin
我将URL添加到这个.http.pos'thttp://localhost:8888/PeopleService/auth/login.php,JSON.stringify(凭证),{headers:headers}),但仍然是空的
if(isset(($_POST['login'])){
$password=$_POST['PASSWORD'];
$phone=$_POST['PHONENUM'];
$password = $conn->real_escape_string($password);
$phone = $conn->real_escape_string($phone);
$arr = array();
$sql = "SELECT EMPID FROM employee WHERE PASSWORD=$password AND PHONENUM=$phone";
$select_users = $conn->query($sql);
if(!$select_users){
die('Query Failed' . mysqli_error($conn));
}
while($row = $select_users->fetch_assoc()) {
$arr= $row
}
echo json_encode($arr);