title: Passing an array from PHP to Javascript using JQuery & JSON
body: <p>I've got a game which refreshes info every 10 seconds from a MySQL database. There will be a JS function which is called each time this happens. I can't get the success function to execute, and I have no idea why. No errors on the console, either.</p>
  
  <p>Javascript:</p>
  
  <pre><code>function refreshStats() {
      console.log("number 1");
      $.ajax({
          url: "refreshData.php",
          type: "POST",
          contentType: "application/json; charset=utf-8",
          dataType : 'json',
          data: { },
          cache: false,
          async: true,
          success: function (msg) {
              if(msg){
                  console.log("number 2");
                  var arr = JSON.parse(msg);
                  document.getElementById("interface_stats").innerHTML =
                      "Fatigue: " + arr[0];
  
              }
  
          }
      });
  }
  </code></pre>
  
  <p>PHP:</p>
  
  <pre><code>&lt;?php
  
  $username = $_POST['user'];
  ini_set('display_errors', 1);
  error_reporting(E_ALL);
  
  $con = mysql_connect("localhost","redacted","redacted");
  if (!$con)
  {
      die('SQL error! Aborting: ' . mysql_error($con));
  }
  $db = mysql_select_db("aftertheend",$con) or die("Database error! Aborting. Inform the admin.");
  $query = "SELECT fatigue, food, water, radiation, condition FROM users WHERE username='TheMightyThor'";
  $result = mysql_query($query, $con);
  
  $data = mysql_fetch_row($result);
  
  $stats = [
      "fatigue" =&gt; $data[0],
      "food" =&gt; $data[1],
      "water" =&gt; $data[2],
      "radiation" =&gt; $data[3],
      "condition" =&gt; $data[4]
      ];
  
  echo json_encode($stats);
  
  
  ?&gt;
  </code></pre>