我必須通過HTTP POST使用Angular JS發送簡單的JSON對象。AngularJS HTTP POST不發送數據
我有一個簡單的NG-CLIK連接功能:
$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);
});
};
我控制器配置爲:
iftttApp.controller('indexController',
['$scope', '$routeParams', '$window', '$http', function ($scope, $routeParams, $window, $http,) { ... });
的POST成功地達到我的servlet成功返回,但是JSON不要放在HTTP消息,POST數據結果爲空。爲什麼?
我的控制器的配置是: 'iftttApp.controller( 'indexController的',[ '$範圍', '$ routeParams', '$窗口', '$ HTTP', 函數($範圍,$ routeParams,$ window,$ http,){...});' – kitsune
「JSON不放在HTTP消息中,POST數據結果爲空」 - 你如何確定這個?您是否使用瀏覽器中的開發人員工具來檢查網絡流量?你是否試圖用一些你沒有在問題中包含的服務器端Java來閱讀它? – Quentin
$ scope.nome和$ scope.regione是否定義? –