在angularjs中设置post前的post数据格式
如何将我的在angularjs中设置post前的post数据格式,angularjs,http-post,Angularjs,Http Post,如何将我的cartPostpost数据发送为: products= [ { "code": "mig-09", "title": "supermig", "quantity": "1" } ] 这是我的http.post $http.post("www.remoteurl.com", { products: cartPost }).success(function(data){ $scope.cart = data; }) 我需要这样做,因为在
cartPost
post数据发送为:
products=
[
{
"code": "mig-09",
"title": "supermig",
"quantity": "1"
}
]
这是我的http.post
$http.post("www.remoteurl.com", {
products: cartPost
}).success(function(data){
$scope.cart = data;
})
我需要这样做,因为在服务器端。post数据将填充在
$products=json\u decode($\u post['products'])
中,否则它将无法工作。我该怎么做?有人能帮我吗?我找到了解决问题的办法
$http({
method: 'POST',
url: 'www.remoteurl.com',
data:'products=' + cartPost, // the solution
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
})
.success(function(response) {
$scope.result = response;
});
cartPost是数组吗?cartPost包含
[{“code”:“mig-09”,“title”:“supermig”,“quantity”:“1”}]
只发送它有效吗$http.post(“www.remoteurl.com”,cartPost)不,post数据必须是这样的products=[{“code”:“mig-09”}]
只有这样才能工作,这是无效的JSON