Login factory $http.post


#1

Hi all, i am developing my first Ionic app. I am trying to add a login functionality that calls the remote method to log in to my framework.
I made a factory like this one:

app.factory('LoginService', function($http, $q) {
	return {
		login: function(user) {
			var deferred = $q.defer();
			$http.post('http://mydomain/users/login.json', user)
			.success(function(response, status){
				deferred.resolve(response);
			})
			.error(function() {
				console.log('SOMETHING WENT WRONG');
			});
                    return deferred.promise;
		}
	}
});

In the “user” variable i have the email and password inserted in the login form.
The problem is that if i pass “user” to the post function, the function itself breaks.
So my question is: how i pass the parameters in post to the function?


#2

Ok i fixed it. I was testing through browser and i needed in my backend to allow headers in this way (php code)
header(‘Access-Control-Allow-Headers’,‘Content-Type’);