0
I need to pass a Array
for Ajax to read it in a script PHP.
Javascript code:
$.ajax({
type: "POST",
url: "vendas_funcoes.php",
data: arrayItens,
success: function(msg){
console.log("ok");
}
});
I’ve tried using the following example I saw, but it didn’t work. I’ve also tried using stringify
and did not roll.
sales_functions.php:
<?php
$data = json_decode(stripslashes($_POST['data']));
// usar foreach para ler o array
foreach($data as $d){
echo $d;
}
?>
How do I get this Array
in the script PHP so I can manipulate it ? The above code apparently does not enter the foreach
that I have in my script .php
.
Would not be
data: {"data": arrayItens}
in Jquery?– Woss
To take the value in this way "$_POST['data']" put the "date" of the jquery in the following form: { data : arrayItens }, that is to say if you define "date" in the php post you take "date", if you wanted another name you can do date : { test: arrayItens } and then in php you’ll have to put $_POST['test']
– Wictor Chaves
Thank you, @Andersoncarloswoss
– Wictor Chaves
This way it will enter my 'foreach' ? How can I test to see if I’m getting the same array ?
– thiaguera94