This must be very simple but I am struggling badly with this. My client is very upset over things not working, although rest of the application I’ve completed but because at the login stage only its not working so client is not able to test it.
In browser it works fine but in emulator and device there is this error -
Response with status: 0 for URL: null
On Server side there is CodeIgniter. Searched, tried a lot but could not find a workable solution. Please check codes below and help me resolve the issue.
ionic.config.json
"proxies": [
{
"path": "/login",
"proxyUrl": "http://www.mydomain.coo/members/login"
},
{
"path": "/update",
"proxyUrl": "http://www.mydomain.coo/members/update"
},
{
"path": "/register",
"proxyUrl": "http://www.mydomain.coo/members/register"
},
login.ts
login() {
this.showLoader('Authenticating...');
this.postData = { isApp: '1', key: 'login', email:this.email, password:this.password };
let data = JSON.stringify(this.postData);
this.auth.login( this.postData ).then((result) => {
this.loading.dismiss();
this.data = result;
if ( this.data.status == true )
{
localStorage.setItem('id', this.data.id);
this.navCtrl.setRoot(TabsPage);
}
else
{
this.showLoader('Invalid Credentials...');
this.loading.present();
setTimeout(() => {
this.loading.dismiss();
}, 2000);
}
}, (err) => {
this.loading.dismiss();
this.presentToast(err);
});
}
auth-service.ts
login(postData) {
return new Promise((resolve, reject) => {
let headers = new Headers( {
'Access-Control-Allow-Origin' : '*',
'Access-Control-Allow-Methods' : 'POST, GET, OPTIONS, PUT',
'Content-Type': 'application/json; charset=UTF-8',
'Accept': 'application/json'
});
this.http.post('/login', JSON.stringify(postData), {headers: headers})
.subscribe(res => {
resolve(res.json());
}, (err) => {
reject(err);
});
});
}
Codeigniter index.php
header(“Access-Control-Allow-Origin: *”);
header(“Access-Control-Allow-Methods: POST, GET, OPTIONS”);
header(“Access-Control-Allow-Headers: X-PINGOTHER, Content-Type”);
header(“Access-Control-Max-Age: 86400”);