I there, I try to use a php-array with ajax to POST it to another php-file. I thought I could do it this way:
<?php
$test_array[] = "dum";
$test_array[] = "dim";
$test_array[] = "dam";
$test_array[] = "dom";
$test_array[] = "düm";
?>
<script type="text/javascript">
$.ajax({ url: 'include.php',
type: 'POST',
data: { my_array : <?php echo json_encode($test_array); ?>
},
success: function(returnData)
alert(returnData);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("XMLHttpRequest="+XMLHttpRequest.responseText+"\ntextStatus="+textStatus+"\nerrorThrown="+errorThrown);
}
});
}
</script>
with include.php looking like this:
echo count($_POST['my_array']);
echo json_decode($_POST['my_array']);
echo $_POST['my_array'];
The problem is, that no array is going to incude.php
The echos give "1düm", means, the length of the $_POST-var is 1 (while the original array is 5), and its entry is only "düm" (which is the last entry of the original array).
It looks like this:
count: 1
json_decode:
$_POST: düm
So, it seams that not the complete array, but only the last entry is POSTed...
How can I get the whole array $test_array to include.php via that ajax-call?
thx in advance...
$test_array['a'] = "dum"; $test_array['b'] = "dim";and so on. Maybe that will help.var_dump(json_decode($_POST['my_array']))?