0
我想通过一些文本输入作为数组字符串到角度控制器。我能够通过使用String key = request.getParameter("key");
如何将字符串数组从html输入传递给Angular http Post?
派单输入作为POST PARAM和得到它的Serlvet这是我的形式
<form ng-controller="FormController" ng-submit="submitForm()" class="ng-valid ng-scope ng-dirty ng-valid-parse">
<p>Text1: <input type="text" name="ancestor" ng-model="blob.ancestor" class="ng-valid ng-dirty ng-touched ng-empty"></p>
<p>Text2: <input type="text" name="ancestor" ng-model="blob.ancestor" class="ng-valid ng-dirty ng-valid-parse ng-empty ng-touched"></p>
<p><input type="submit" class="btn btn-primary" value="Confirm"></p>
</form>
,这是我的JS脚本:
var app = angular.module('myApp', []);
app.controller('FormController', FormController);
FormController.$inject = ['$scope', '$http', '$httpParamSerializerJQLike'];
function FormController($scope, $http, $httpParamSerializerJQLike) {
$scope.blob = {};
$scope.submitForm = function() {
alert(JSON.stringify($scope.blob));
$http({
method : 'POST',
url : '/javaAngularJS',
data: $httpParamSerializerJQLike($scope.blob),
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8;'
}
});
};
}
同样,我能够发送单个参数,但我想发送具有多个值的“祖先”,并使用我的Post方法在servlet中使用String ancestors[] = reuest.getParameterValues("ancestor");
。
thx!它为我工作。顺便说一句,我使用'.then(function successCallback(response){}'insted'.success(){}'已被弃用的Angular版本> 1.4.x –