I don't think that my question is so difficult to answer. I haved try t search all over but I don't get a sucess answer.
I have a JSON Object shaped with severals Array like this:
{1:{7:["Ready","Pro","WAK", "2"],16:["Pausa","Contra","KAW"]},8:["Cleab","Pro","WAK", "1"],16:["Build","Contra","KAW"]}
This is very good running because I can se the structure of the Json in the console
I want to send this Json to PHP and there read the Content and print or send to the DB, ect. I haved read something about serializearray()
but this is only working with Forms elements. Most of the examples very good explained are in the oposite direccion, sending a Json to the CLient with the uses of the PHP function json_encode
. This is not my case, I want the oposite from Jquery to PHP. I also read something about json_decode
, but I don't know how to use it.
Here is my js code:
var Obj1= {}
var Obj2= {};
var key;
$("table tr.data").each(function(i) {
var row = [];
key = $(this).find('td').eq(0).find('input').val();
row.push($(this).find('td').eq(1).text());
row.push($(this).find('td').eq(2).text());
Obj2[key] = row;
});
Obj1[select.val()] = Obj2;
var DataJSON = JSON.stringify(Obj1);
alert(DataJSON);
$.ajax({
data: DataJSON,
url: 'process.php,
type: 'POST',
dataType: 'json',
beforeSend: function (){
alert('Information wird gespeichert');
},
success: function () {
alert('Information wurde gespeichert');
},
error: function(){
alert('Server antwortet nicht. Fehler..');
}
});
And this my php code only to read what I received from the client:
header('Content-Type: application/json');
$data1 = json_decode($data);
foreach ($data1 as $name => $value) {
echo $name . ':';
foreach ($value as $entry) {
echo ' ' . $entry;
}
}
Can PLEASE somebody tell me what I'm doing wrong? How is the correct procedure? Thx!!