I'm stuck, I have googled and searched here on the stack.
First, I create a JS obj:
var formData = {};
//LOOP THREW TABLE ROWS
$("tr.element_row").each(function(index, element){
var $this = $(this);
var $inputs = $this.find("input.formData");
formData[index] = {};
//LOOP THREW INPUTS
$.each($inputs, function(n, e){
//this is each input in this tr
if( $(this).attr('name') == 'el' ){
formData[index]['el'] = $(this).val();
} ...
Then I convert it with JSON stringify:
var myJSON = JSON.stringify(formData);
//RESULT (console.log(myJSON))
{"0":{"obj":"1234","el":"1","lit":"1","height":"","type":"","length":"","width":"","weight_kg":"","proj":"BC"},"1":{"obj":"1234","el":"2","lit":"1","height":"","type":"","length":"","width":"","weight_kg":"","proj":"BC"},"2":....
Then I send it with ajax to PHP:
$.ajax({
url: 'php/add_elementdata.php',
method: 'post',
dataType: "json",
data: myJSON,
Then i do a var_dump($_POST)
//RESULT
array(1) {
["{"0": {"obj":"1234","el":"1","lit":"1","height":"","type":"","length":"","width":"","weight_kg":"","proj":"BC"},"1":{"obj":"1234","el":"2","lit":"1","height":"","type":"","length":"","width":"","weight_kg":"","proj":"BC"},"2":{"obj":"1234","el":"3","lit":"1","height":"","type":"","length":"","width":"","weight_kg":"","proj":"BC"},"3":{"obj":"1234","el":"4","lit":"1","height":"","type":"","length":"","width":"","weight_kg":"","proj":"BC"},"4":{"obj":"1234","el":"5","lit":"1","height":"","type":"","length":"","width":"","weight_kg":"","proj":"BC"}}"]=> string(0) ""}
Then I want to create a multidimensional array of this.. array..string..
$arr = json_decode($_POST);
or
$arr = json_decode($_POST, true);
echo $arr;
But $arr returns empty. why?
var_dump($arr);not echo its an std objectjson_decode($_POST[0]);to only get the first array.data: {'myJSON':myJSON}then getting it with$_POST['myJSON']