title: $.ajax post array as Json to PHP. $_POST = empty
body: <p>Ok, I spend many time on this, I don't get what I'm doing wrong. </p>
  
  <p><strong>It seems impossible to get the data in the PHP file</strong>.</p>
  
  <ol>
  <li>First I call many times "copy" to fill the "result" array.</li>
  <li>Then, I call the <code>$.ajax</code> method</li>
  <li>In the process.php $_POST is empty</li>
  </ol>
  
  <p><em>--> In the PHP <code>$x</code>, <code>$y</code> or <code>$time</code> or not null but not empty.</em></p>
  
  <blockquote>
    <p><strong>Edit 2:</strong> </p>
    
    <p>Ok - with json_last_error() i saw that it's my json which is
    "Syntax error: malformed". But i don't know how to encode it better than what i'm
    doing. </p>
    
    <p><strong>So i cheat by adding a stripslashes() on the $_POST.</strong> </p>
    
    <p>[{\"x\":104,\"y\":218,\"timestamp\":1349476537434},{\"x\":90,\"y\":202,\"timestamp\":1349476537469},{\"x\":82,\"y\":192,\"timestamp\":1349476537487},{\"x\":71,\"y\":177,\"timestamp\":1349476537514},{\"x\":68,\"y\":174,\"timestamp\":1349476537568},{\"x\":68,\"y\":173,\"timestamp\":1349476537801},{\"x\":68,\"y\":174,\"timestamp\":1349476538478},{\"x\":68,\"y\":175,\"timestamp\":1349476538512},{\"x\":68,\"y\":175,\"timestamp\":1349476538579},{\"x\":69,\"y\":175,\"timestamp\":1349476538678}]</p>
    
    <p><strong>Edit 1:</strong></p>
    
    <p><strong>The posted data seems to be good (look under), and i finish in the
    "success function".</strong>   </p>
    
    <p>[{"x":529,"y":97,"time":1349469608703},{"x":385,"y":331,"time":1349469608720},.....]</p>
  </blockquote>
  
  <p><strong>JS Side - index.php :</strong> </p>
  
  <pre><code>&lt;script src="jquery.js"&gt;&lt;/script&gt;    
  
  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></pre>
  
  <p><strong>PHP Side - process.php :</strong> </p>
  
  <pre><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></pre>