title: My ajax JSON object is recognized as "Undefined"
body: <p>I am having troubles with my ajax call. When I try to alert the result it keeps resulting as Undefined.</p>
  
  <p>Both alerts are resulting to undefined.
  I am not too sure if I am coding this correctly, please help me if I am.</p>
  
  <p>Q: If I am accessing it incorrectly, how exactly would I access the skill property/index.</p>
  
  <p><strong>JQUERY/JSCRIPT</strong></p>
  
  <pre><code>$(document).ready(function(){
      // Skill sort on change
      $('#order_by').on('change', function() {
          $.ajax({
              type: "POST",
              url: "sort_skill_be.php",
              dataType: "json",
              data: {skill:this.value}  
          }).done(function(result){
                  alert(result[0].skill);
          })
      });
  });
  </code></pre>
  
  <p><strong>PHP FILE: This method receives a statement and places an "object" array to an overall array.</strong></p>
  
  <pre><code>function helpFetchPostInfo($stmt){
      $results = $stmt-&gt;fetchAll();
      $recent_posts = array();
      foreach ($results as $row){
          $post = array(
              'username' =&gt; $row['username'],
              'steam' =&gt; $row['steam'],
              'skill' =&gt; $row['skill'],
              'description' =&gt; $row['description'],
              'date' =&gt; $row['date'],
          );
          array_push($recent_posts, $post);
      }
      return json_encode($recent_posts);
  }
  </code></pre>
  
  <p>Thank you for the assistance it is much appreciated</p>
  
  <pre><code>function sortSkill($skill){
      // If All skill is selected display posts normally
      if ($skill == 'All'){
          displayPosts();
          exit;
      }
      $db = connect();
      $sql = "SELECT * FROM users LEFT JOIN posts 
              ON users.idUsers = posts.fkuser 
              WHERE posts.fkuser IS NOT NULL and users.skill=:skill
              ORDER BY date DESC";
      $stmt = $db-&gt;prepare($sql);
      $stmt-&gt;execute(array(':skill' =&gt; $skill));      
      if ($stmt-&gt;rowCount() == 0){
          // Nothing has returned
          unset($_SESSION['recent_posts']); // Reset session of posts if no posts appear.
      } 
      else
      {
          $recent_posts = helpFetchPostInfo($stmt);
          return $recent_posts;
      }
  }
  </code></pre>
  
  <p>Sort skill is being called in a seperate php file called sort_skill_be.php, which is called from the jquery when a selection is changed.</p>
  
  <pre><code>&lt;?php
  session_start();
  include 'database.php';
  $skill_sort = $_POST['skill'];
  sortSkill($skill_sort);
  header('Location:index.php'); 
  ?&gt;
  </code></pre>
  
  <p>EDIT: added JSON datatype to jquery</p>
  
  <p>Now my problem is the alert is not being called at all anymore.</p>