我在AngularJS中有一个数组,我希望通过$http
传递来处理PHP(后端),但我无法做到。我可以毫无问题地通过$scope.myForm.shopList
,但是当我发送$scope.myForm
时,php不会收到任何数据。
角:
goSoft.controller('createShop', function($scope, $http){
$scope.myForm = [];
$scope.myForm.shopList = [];
$scope.shopListAdd = [{
cod_prod : '',
ref_prod : '',
cant: '',
fabricante : '',
fecha_vence : '',
vr_compra:'',
vr_venta:'',
iva:''
}];
$scope.add = function(shopAdd) {
var index = $scope.shopListAdd.indexOf(shopAdd);
$scope.shopListAdd.splice(index, 1);
$scope.myForm.shopList.push(angular.copy(shopAdd))
$scope.shopListAdd.push({
cod_prod:'',
ref_prod:'',
cant: '',
fabricante : '',
fecha_vence : '',
vr_compra:'',
vr_venta:'',
iva:''
})
}
$scope.submitForm = function(){
$http.post('../compras/objCompra.php?type=1', {datos:$scope.myForm}).success(
function(data){
console.log(data);
})
}})
PHP:
$json = json_decode(file_get_contents("php://input"));
print_r($json);
答案 0 :(得分:0)
我通过更改$ scope.myForm = {}
中的键来解决它$scope.myForm = {};
$scope.myForm.shopList = [];
$scope.shopListAdd = [{
cod_prod : '',
ref_prod : '',
cant: '',
fabricante : '',
fecha_vence : '',
vr_compra:'',
vr_venta:'',
iva:''
}];
php和我这样做了:
print_r($data = json_decode(file_get_contents("php://input"), true));