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

问题描述 投票:0回答:1

我想以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");
});
angularjs servlets angularjs-http
1个回答
1
投票

您需要在控制器中注入$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");
});
© www.soinside.com 2019 - 2024. All rights reserved.