我在 angularjs 中有一个数组,示例如下。
$scope.order.qty='20';
$scope.order.adress='Bekasi';
$scope.order.city='Bekasi';
这个数组可以用这个代码发布
$http({
method : 'POST',
url : '<?php echo base_url(); ?>add_order',
data : $scope.order,
headers : {'Content-Type': 'application/x-www-form-urlencoded'}
})
我可以得到所有变量
$_POST = json_decode(file_get_contents('php://input'), true);
$_POST['qty'];
$_POST['address'];
$_POST['city'];
但我很困惑,如果数组是这样的多维:
$scope.items[1].kode_produk='PR_1';
$scope.items[2].kode_produk='PR_2';
$scope.items[3].kode_produk='PR_3';
如何像这样从多维数组中发布和获取变量?
您可以像这样传递数组:
$http({
method : 'POST',
data : { items: $scope.items }
...
})
获取数据:
$_POST = json_decode(file_get_contents('php://input'), true);
$items = $_POST['items'];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)