如何在 Angularjs 中将数据作为 ¶meter=value 对发布到 servlet



我想以key=value对将数据发布到servlet,而不是以angularjs中的json格式。这是我的代码:

$http({
method : 'POST',
url : 'login.do?mode=registration',
data : {
firstname : $scope.firstname,
lastname : $scope.lastname,
email : $scope.email,
password : md5.createHash($scope.password)
},
headers : { 'Content-Type': 'application/json' }
}).success(function(data){
$location.path("/login");
});

您需要在控制器中注入$httpParamSerializer并使用它:

var requestData = {...} // Your object
$http({
method : 'POST',
url : 'login.do?mode=registration',
data : $httpParamSerializer(requestData),
headers : { 'Content-Type': 'application/json' }
}).success(function(data){
$location.path("/login");
});

相关内容

最新更新