title: how to access returned data in ajax from php?
body: <p>OK I might have some syntax problem that I cant locate but I think something else is the problem.</p>
  
  <p>I have a .php file that selects multiple values from a database and than that result is 'echo' back to the ajax call where it comes from.</p>
  
  <p>The .php looks like this:</p>
  
  <pre><code>&lt;?php
      require("../config/db.php");
  
      $db = mysql_connect(DB_HOST, DB_USER, DB_PASS)or die("Error connecting to database.");
      mysql_query("SET NAMES UTF8");
      mysql_select_db(DB_NAME, $db)or die("Couldn't select the database."); 
  
      $query = "SELECT online_users, chat_messages, cards_order FROM track_changes LIMIT 1";
      $result = mysql_query($query, $db) or die(mysql_error().': '.$query);
      $row = mysql_fetch_array($result);
  
      $changes = array('online_users'=&gt;$row['online_users'],
                  'chat_messages'=&gt;$row['chat_messages'],
                  'cards_order'=&gt;$row['cards_order']);
  
      echo json_encode($changes, JSON_FORCE_OBJECT);
  ?&gt;
  </code></pre>
  
  <p>than the jQuery ajax call looks like this:</p>
  
  <pre><code>$(document).ready(function() {
  $.ajax({ 
      type: 'POST',
      url: '/kanbannew/php_scripts/track_changes.php',
      data: { },
      async: false,
      success: function (data) {      
          console.log(data);
          var users = data.online_users;
          var chat = data.chat_messages;
          var cards = data.cards_order;
          console.log("Online users: " + users + "\nChat messages: " + chat + "\nCards order: " + cards);
      },
      error: function(xhr, desc, err) {
          console.log(xhr);
          console.log("Details: " + desc + "\nError:" + err);
      }
  }); // ajax end
  });
  </code></pre>
  
  <p>The problem is in the first alert i get the key:values like</p>
  
  <pre><code>{"online_users":"0","chat_messages":"0","cards_order":"0"}
  </code></pre>
  
  <p>but in the second alert i get undefined for every value:</p>
  
  <pre><code>Online users: undefined
  Chat messages: undefined
  Cards order: undefined
  </code></pre>
  
  <p>This prints are from chrome conzole.
  Any ideas why I cant access the zero's??</p>