MR KHAN COMUTI Leader MR KHAN COMUTI Leader - 1 year ago 66
Ajax Question

$_POST returning Array () and echoes nothing if I try to index

I am trying to pass an object (I think its an object( its an associative array/dictionary with an indexed array for values)) to a PHP file so that I can insert data into a database. Every time I try to access the contents of the array in PHP it returns Array() or Array depending on what I try. I have tried to user $.ajax() as well but results in the same problem.

function postData()
data = JSON.stringify(dataObject);
window.location.href = "submit_order.php";

This is what the data structure looks like after using JSON.stringify()

{"order":[["2","chicken panini","3.95",1],["1","cakes","3.55",1]]}

This is what I am trying to access the values and the data structure itself. As you can see I have tried all sorts.

echo $order[0][0];
echo $_POST['order'][0][0][1];
foreach ($_POST as $key => $value) {
echo $key;

When I print_r($_POST); it gives me Array()

{"order":[["2","chicken panini","3.95",1],["1","cakes","3.55",1],["3","big_cake","2.55",1]]} is sent with the POST request.

Answer Source
function postData()
    data = JSON.stringify(dataObject);
    $.post( "submit_order.php", function( data ) {

try this function instead.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download