title: Send data with AJAX and receive in PHP
body: <p>I'm having a script which is generating a JSON array, based values user have selected. These values are sent as a JSON with AJAX to a PHP script which should receive this values and process it.</p>
  
  <p>What could be wrong?</p>
  
  <p>JSON (That is sent):</p>
  
  <pre><code>[{
    "Pages":
           {"name":" Page Name 1",
            "id":"252456436636644"}
           },
    {
     "Pages":{
            "name":" Page Name 2",
            "id":"345345435435232"
            }
  }]
  </code></pre>
  
  <p>Jquery:</p>
  
  <pre><code>var json_pages = JSON.stringify(publish);
  
  $.ajax({
      url: "post.php",
      type: "post",
      data: { PublishToPages: json_pages },
      success: function(){},
      error: function(){}   
  }); 
  </code></pre>
  
  <p>Problem is that the JSON I recieve from PHP isn't getting the data,</p>
  
  <pre><code>if($_POST['PublishToPages']) {
  
      $json = $_POST['PublishToPages'];
  
      $array = json_decode($json, true);
  
      foreach($array as $item) { 
          $page_id = $item['Pages']['id'];
          echo $page_id;  
      }
  }
  </code></pre>
  
  <p>If I manually put in the JSON in the PHP script like this it Works,</p>
  
  <pre><code>if ($_POST['PublishToPages']) {
  
      $json = '[{"Pages":{"name":" Page Name","id":"234545355345435"}},{"Pages":{"name":" Page Name 2","id":"345345435435435435"}}]';
  
      $array = json_decode($json, true);
  
      foreach($array as $item) { 
      $page_id = $item['Pages']['id'];
          echo $page_id;  
      }
  }
  </code></pre>