title: Sending JSON via AJAX to PHP using jQuery
body: <p>I am trying to send JSON to a PHP file using jQuery AJAX, basically what I am trying to do is get the values and id's of a bunch of child elements and then assign them to a JSON object and then send that object via ajax to the PHP file which would then process it and enter it into a database. </p>
  
  <p>Here is my code,</p>
  
  <p>Javascript/jQuery:</p>
  
  <pre><code>function test(){
      var selects = $('#systems_wrapper').find('.dropDowns');
      var newArray = new Array();
  
      selects.each(function(){
          var id = $(this).attr('id');
          var val = $(this).val();
          var o = { 'id': id, 'value': val };
  
          newArray.push(o);
      });
  
      $.ajax({
              type: "POST",
              url: "qwer.php",
              dataType: 'json',
              data: { json: newArray }
          });
  
  }
  </code></pre>
  
  <p>PHP:</p>
  
  <pre><code>&lt;?php
      $json = $_POST['json'];
      $person = json_decode($json);
  
      $file = fopen('test.txt','w+');
      fwrite($file, $person);
      fclose($file);
  
      echo 'success?';
  ?&gt;
  </code></pre>
  
  <p>It creates the file, but it is completely blank, any idea what it could be?</p>
  
  <p>Thanx in advance!</p>