I have to send a simple JSON object using Angular JS thorough a HTTP POST.
I have a simple ng-clik linked function:
$scope.requestGoogleAuth = function() {
var googleCredentials = {
email: '[email protected]',
password: 'a2s4d'
};
console.log(JSON.stringify(googleCredentials));
/*$http({
url: '/MyServlet',
method: "POST",
data: JSON.stringify(googleCredentials),
headers: {'Content-Type': 'application/json'}
})*/
$http.post("/MyServlet", JSON.stringify(googleCredentials)).then(function success(response) {
$('#loginGoogleModal').modal('hide');
$("#notificationsWrapper").notify(
"Logged with Google",
{
className: 'success',
position: 'bottom right'
}
);
$scope.googleLogged = true;
console.log($scope.googleLogged);
}, function error(response) {
$('#loginGoogleModal').modal('hide');
$("#notificationsWrapper").notify(
"Failed to login with Google",
{
className: 'error',
position: 'bottom right'
}
);
$scope.googleLogged = false;
console.log($scope.googleLogged);
});
};
My controller configuration is:
iftttApp.controller('indexController',
['$scope', '$routeParams', '$window', '$http', function ($scope, $routeParams, $window, $http, ) { ... });
The POST reaches successfully my servlet returning success, however the JSON isn't put in the HTTP message, the POST data results empty. Why?
iftttApp.controller('indexController', ['$scope', '$routeParams', '$window', '$http', function ($scope, $routeParams, $window, $http, ) { ... });