title: Struggling to decode JSON in jquery ajax success callback from PHP script
body: <p>I've been trying to find an answer for this for hours but really struggling.</p>
  
  <p>I have a simple jquery Ajax function which sends data to a PHP script. The data is then used to conduct a MySQL query and the results are included as an array. I'm sending the array back using <code>json_encode</code> but can't work out how to display the array at the other end. I've posted the code below. The <code>console.log</code> is displaying <code>Object {modules: Array[0]}
  </code>. There should be 3 entries in the array.</p>
  
  <p><strong>The PHP</strong></p>
  
  <pre><code>&lt;?php
   include_once('../../dbconnect.php');
  
  $name = $_POST['uploadname'];
  
  $query = "SELECT * FROM marking_assignments WHERE name = '$name'";
  $details = $conn-&gt;query($query);
  $modules = array();
  
  while ($row = $details-&gt;fetch_assoc()){
   $modules[] = $row['unit'];
  }
  
  $dataarray = array("modules"=&gt;$modules);
   echo json_encode($dataarray);
  ?&gt;
  </code></pre>
  
  <p><strong>The jQuery</strong></p>
  
  <pre><code>  var uploadname;
  
    $("#uploadname").blur(function(){
     uploadname = $(this).val();
     $.ajax({
              url: "uploadnames.php",
              type: "POST",
              data: {uploadname: uploadname},
              dataType: 'json',
              success: function(data){
              console.log(data);
               }
              });
  
           });
  </code></pre>