$.ajax post array as Json to PHP. $_POST = empty

Infamous

New Member
Ok, I spend many time on this, I don't get what I'm doing wrong. It seems impossible to get the data in the PHP file.[*]First I call many times "copy" to fill the "result" array.[*]Then, I call the \[code\]$.ajax\[/code\] method--> In the PHP \[code\]$x\[/code\], \[code\]$y\[/code\] or \[code\]$time\[/code\] or not null but not empty.JS Side - index.php : \[code\]<script src="http://stackoverflow.com/questions/12753667/jquery.js"></script> results = new Array();function copy(x, y, time) { var o = { 'x': x, 'y': y, 'time': time }; results.push(o);}function save() { var encoded_results = JSON.stringify(results); $.ajax({ url: "process.php", type: 'POST', data: { "results" : encoded_results }, success: function(data, status, xhr) { alert(data); console.log(data); console.log(xhr); }, error: function (xhr, ajaxOptions, thrownError) { alert(xhr.status); alert(thrownError); } });}\[/code\]PHP Side - process.php : \[code\]if(isset($_POST["results"])){ $result_json = $_POST["results"]; $JSONArray = json_decode($result_json, true); if($JSONArray !== null) { $x = $JSONArray["x"]; $y = $JSONArray["y"]; $time = $JSONArray["time"] }}\[/code\]
 
Top