Hi,
I’m having an issue logging in to my app on an android device.
This is the code I’m using:
var login = function(user, callback) {
show_spinner();
$http({
url: BACKEND_URL.baseURL+BACKEND_URL.loginURL,
method: "POST",
headers: {"Content-Type": "application/x-www-form-urlencoded"},
data: $.param({email:user.username, password:user.password})
}).success(function(data, status, headers, config) {
hide_spinner();
var responseData = JSON.parse(JSON.stringify(data));
if(responseData.isValid == "invalid")
{
//alert("Username and password are not valid. Please try again.");
$ionicPopup.alert({
title: 'Failure',
template: 'Username and password are not valid. Please try again.'
});
}
else{
var userData = responseData.user;
console.log(userData);
user_id = userData.id;
user_email = userData.email;
storeUserCredentials(user.username, user.password);
callback("success");
}
}).error(function(data, status, headers, config) {
callback("failure");
hide_spinner();
$ionicPopup.alert({
title: 'Error',
template: data
});
});
};
If I test the app in my browser (ionic serve), it all works well.
If I test it on iPhone, it works well too.
Except on an android emulator or device, it won’t log in.
If I test it with the ionic view app, it does work (on every device)
Does anybody have any tips what to do?
I run the command: cordova run android, it install and runs on my device, but when i want to log in, it calls the error function from above immediately:
error(function(data, status, headers, config) {
callback("failure");
hide_spinner();
$ionicPopup.alert({
title: 'Error',
template: data
});
Also, I started searching and ended on the ‘whitelist’ plugin, I already added this to my config.xml file
<access origin="*"/>
<allow-intent href="*.ionic.io"/>
<allow-intent href="*"/>
<allow-navigation href="*" />
Just to test to see if it would make any difference, but it didn’t.
Thank you!