角$ HTTP POST中发送数据 [英] Sending data in angular $http post
问题描述
我似乎有一些困难发送的一个选择项中选出一个VAL成角一个新的%HTTP POST。
I seem to be having some difficulty sending a val of a selected of a selected item into a new %http post in angular.
我做了以下内容:
$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即时试图发送)的previous下拉在该事件被触发。 $ scope.scope1.id似乎存储就好了,当我CONSOLE.LOG它不过当我看到在dev的控制台被格式化很奇怪的是,像这样的FORMDATA -
Where $scope.scope1.id is the val (which is the id im trying to send) of the previous drop down in which this event is triggered. $scope.scope1.id seems to be storing just fine when I console.log it however when I look at the formdata in the dev console it is formatting very oddly like so -
{"id":2}:
这看起来是认识整个第一项为重点。解决这个办法?我曾尝试过各种想法,但没有成功。
It looks like it is recognizing the whole first item as the key. Any way around this? I have tried various ideas with no success.
谢谢!
推荐答案
您需要使用PARAMS,而不是数据。 AngularJs文档
You need to use params instead of data. AngularJs docs
$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;
});
};
这篇关于角$ HTTP POST中发送数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!