louadesoov
New Member
I want to post Javascript Array Object via Ajax to PHP. Then at PHP end, i still want to use that object as an true Array. Below is my approach so far still not successful in terms of using the incoming object as an \[code\]Array\[/code\] at PHP side. I can just parse it as the \[code\]string\[/code\].Javascript:\[code\]var myObj = { fred: { apples: 2, oranges: 4, bananas: 7, melons: 0 }, mary: { apples: 0, oranges: 10, bananas: 0, melons: 0 }, sarah: { apples: 0, oranges: 0, bananas: 0, melons: 5 } }\[/code\]Then, Javascript/JQuery to send via AJAX:\[code\]$.ajax({ type: "POST", url: "ajax.php", dataType: "JSON", data: { "data" : JSON.stringify(myObj) }}).success(function( response ) { alert(response);});\[/code\]Then parse at PHP:\[code\]$data = http://stackoverflow.com/questions/15832737/json_decode( $_POST["data"] );echo json_encode( $data["fred"] );echo json_encode( $data["fred"]["apples"] );echo json_encode( $data["fred"]->apples );echo json_encode( $data[1] );\[/code\]
- Any of above \[code\]echo\[/code\] returns blanks, back to the browser.
- So seems data is there, but how can i parse this data as in the proper truely \[code\]ARRAY\[/code\] manner at \[code\]PHP\[/code\] end, please?