Im new with NodeJS and Im trying to send data to server with Angular
$scope.logearse = function () {
$http({
method: "POST",
url: "http://localhost:8888/login",
data: $scope.usuario
}).then(function successCallback(response){
console.log(response)
}, function errorCallback(error){
alert("No se han podido enviar los datos")
})
}
But in the server when I try to receipt the request is always {}
http.createServer(function(peticion, respuesta){
console.log(peticion.url)
console.log(peticion)
// We begin with "login"
if (peticion.url == "/login") {
console.log("Inside of Login)
var datosUsuarioLogin = '';
peticion.addListener("data", function(chunk) {
datosUsuarioLogin += chunk;
// function called when a new chunk of data is recibed
});
peticion.addListener("end", function() {
// When the data is recibed is transformed in JSON
var datosUsuarioLoginObjeto = querystring.parse(datosUsuarioLogin);
recuperarDatos(datosUsuarioLoginObjeto, respuesta);
console.log(datosUsuarioLoginObjeto) //return {}
});
//End of LOGIN "if"
}
}).listen(8888)
The thing is the same code works if I use a form with a regular submit but no if I try to use the $http of ANGULAR.
I try to use "params" instead of "data" but "params" transform the data in the URL and the code dont works.