1
→ $scope.items = [];
→ dados = $('#meu_form').serialize();
I wonder: how to send/receive/read the arrays above to a PHP page?
Javascript:
app = angular.module("app",[]);
app.controller("controlador", ["$scope", "$http",
function($scope, $http){
$scope.items = [];
$scope.submitForm = function() {
var dados = $('#meu_form').serialize();
$http({
method : 'POST',
url : 'pagina.php',
data :
headers : {'Content-Type': 'application/x-www-form-urlencoded'}
})
};
php page.
$dados = json_decode(file_get_contents('php://input'), true);
foreach ($dados as $key => &$value) {
$codigo = $value['codigo'];
$quantidade = (float)$value['quantidade'];
$v_total = $value['v_total'];
}
$nome = $_POST['nome'];
$email = $_POST['email'];
Within
$http
indata :
try to putdata : {scope: $scope.items, dados: dados }
, and in PHP$_POST['scope']
and$_POST['dados']
to recover respectively.– Leonardo
Thanks for the @ivcs attention, but it didn’t work. I can invite you to chat?
– lucasbento
Strange, here worked, returns some error in the console? I tried with the arrays:
var lista1 = ['item1', 'item2', 'item3']; var lista2 = ['item1', 'item2', 'item3', 'item4'];
and the date with{ lista1: lista1, lista2: lista2 }
, in PHP I only walked the$_POST
and concatenated the keys into a string, the result was expected.– Leonardo
-- Can yes :)))
– Leonardo
Just a minute, @ivcs.
– lucasbento
http://chat.stackexchange.com/rooms/51217/como-passar-multiplos-arrays-para-pagina-em-php
– lucasbento