I have this JavaScript array:
testarr = new Array();
testarr[0] = new Array();
testarr[0]["#FFFFFF"] = "White";
testarr[0]["#FFFFFF"] = new Array();
testarr[0]["#FFFFFF"]["#FFFFFA"] = "A";
testarr[0]["#FFFFFF"]["#FFFFFB"] = "B";
testarr[0]["#000000"] = "Black";
testarr[0]["#000000"] = new Array();
testarr[0]["#000000"]["#000001"] = "A1";
testarr[0]["#000000"]["#000002"] = "B1";
I use this jQuery AJAX post method:
$.ajax({
type: 'POST',
url: 'backEndFile.php',
dataType: 'json',
data: {cat:testarr},
success: function(data) {
if (data.success === true) {
alert("SUCCESS");
} else {
alert("NOT SUCCESS")
}
}
});
my backEndFile.php
<?php
var_dump($_POST);
?>
In backEndFile var dump prints: array(0) {} not found me post array.
if I change me array keys from string to digits like this:
testarr[0] = new Array();
testarr[0][0] = "White";
testarr[0][0] = new Array();
testarr[0][0][0] = "A";
testarr[0][0][1] = "B";
testarr[0][1] = "Black";
testarr[0][1] = new Array();
testarr[0][1][0] = "A1";
testarr[0][1][1] = "B1";
then prints correctly
mewithmy. It's unrelated, but it's worth it fixing them.data: JSON.stringify({cat:testarr}). Currently jQquery might be seriliazing your object to url encoded form.echo file_get_contents('php://input');