Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在angularjs中设置post前的post数据格式_Angularjs_Http Post - Fatal编程技术网

在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