以角$ httppost发送数据

我似乎在将一个选定项目的val发送到角度的新%httppost时遇到了一些困难。

我正在做以下事情:

$scope.scope1Change = function() { //Build URL based on selection $http({ method: 'POST', url: '/listAreasByScope', headers: {'Content-Type': 'application/x-www-form-urlencoded'}, data: { id: $scope.scope1.id } }) .success(function(data){ $scope.array2 = data.scopes; }); }; 

其中$ scope.scope1.id是触发此事件的上一个下拉列表的val(即尝试发送的id)。 $ scope.scope1.id似乎在我console.log时存储得很好但是当我在开发控制台中查看formdata时,它的格式非常奇怪,就像这样 –

  {"id":2}: 

看起来它正在将整个第一项视为关键。 有什么方法吗? 我尝试了各种各样的想法但没有成功。

谢谢!

您需要使用params而不是数据。 AngularJs文档

 $scope.scope1Change = function() { //Build URL based on selection $http({ method: 'POST', url: '/listAreasByScope', headers: {'Content-Type': 'application/x-www-form-urlencoded'}, params: { id: $scope.scope1.id } }) .success(function(data){ $scope.array2 = data.scopes; }); };