I'm creating a mobile application with the Ionic framework, using AngularJS. I've created the following factory to handle the HTTP requests:
.factory('Webservice', function($http) {
var serviceURL = "http://www.urltowebservice.com/webservice";
return {
login: function(username, password){
$http.post(serviceURL + "/login", {username: username, password: password}).then(function(resp) {
console.log(resp);
}, function(err) {
console.error(err);
});
},
personalData: function(userID){
$http.get(serviceURL + '/personal-data/' + userID).then(function(resp) {
console.log(resp);
}, function(err) {
console.error(err);
});
}
}
});
When I call the personalData method, the HTTP request works fine and as aspected:
Webservice.personalData(193);
But when I call the login method, the HTTP POST request is resulting in an internal server error 500:
Webservice.login("my@credentials.com", "a1b2c3d4e5");
I have already tried to make the same HTTP post request using an Ajax call as followed (this works perfectly):
$.post("http://www.urltowebservice.com/webservice/login",
{
username: "my@credentials.com",
password: "a1b2c3d4e5"
},
function(data, status){
alert("Data: " + data + "\nStatus: " + status);
});
Why is the AngularJS HTTP POST request not executed as expected, while the same Ajax request is working like a charm? Any help would be appreciated!