title: Json returns undifined
body: <p>Good day guys I have the following login page. Which I access using ajax from my view page. The problem the data that is returned when I try to display on ajax I get an error on the console.</p>
  
  <blockquote>
    <p>login.js:35 Uncaught TypeError: Cannot read property 'success' of
    undefined
        at Object.success (login.js:35)
        at i (jquery-2.2.0.min.js:2)
        at Object.fireWith [as resolveWith] (jquery-2.2.0.min.js:2)
        at z (jquery-2.2.0.min.js:4)
        at XMLHttpRequest. (jquery-2.2.0.min.js:4)</p>
  </blockquote>
  
  <pre><code>&lt;?php
  ob_start();
  
  function __autoload($classname)
  {
  
      require_once("../../database/$classname.php");
  }
  
  
  class userlogin extends database
  {
  
      private $errors = array();
      private $message = array();
      private $redirect = array();
      private $data = array();
      private $username;
      private $password;
  
      function login()
      {
  
          if (empty($_POST['username']) || empty($_POST['password'])) {
  
              $this-&gt;message['error'] = "Please enter username and password";
          } else {
  
              $this-&gt;username = $_POST['username'];
              $this-&gt;password = $_POST['password'];
  
  
              try {
                  $this-&gt;stmt = $this-&gt;dbh-&gt;prepare("SELECT adminID,adminEmail,adminPassword,admintype FROM admin where adminEmail = ? ");
  
                  $this-&gt;stmt-&gt;execute(array(
                      $this-&gt;username
                  ));
  
                  $this-&gt;results = $this-&gt;stmt-&gt;fetchall();
  
                  if (count($this-&gt;results) &gt; 0) {
                      foreach ($this-&gt;results as $key =&gt; $row) {
                          if (password_verify($this-&gt;password, $row['adminPassword'])) {
                              $_SESSION['user']  = $row['adminID'];
                              $_SESSION['email'] = $this-&gt;username;
                              $_SESSION['usertype'] = $row['admintype'];
  
                              switch ($row['admintype']) {
                                  case 's':
                                      $this-&gt;redirect['redirect'] = "seo/index.php?route=home";
                                      break;
                                  case 'a':
                                      $this-&gt;redirect['redirect'] = "admin/index.php?route=home";
                                      break;
                              }
  
                              $this-&gt;message['success'] = "ok";
  
                          } else {
  
                              $this-&gt;message['error'] = "Username and password does not match";
                          }
  
                      }
  
                  } else {
  
                      $this-&gt;message['error'] = "Username does not exist";
                  }
  
              }
              catch (PDOException $pdo) {
  
                  $this-&gt;error = $pdo-&gt;getMessage();
  
                  error_log($this-&gt;error);
              }
  
              $this-&gt;data['message']  = $this-&gt;message;
              $this-&gt;data['redirects'] = $this-&gt;redirect;
  
              ob_end_clean();
  
              echo json_encode($this-&gt;data);
  
          }  
  
      }
  
  
  }
  
  if ($_SERVER['REQUEST_METHOD'] == "POST") {
  
      $login = new userlogin();
      $login-&gt;login();
  }
  ?&gt;
  </code></pre>
  
  <p>and my js </p>
  
  <pre><code>function proccessLogin(){
  
          var username = $('input[type="email"][name="email"]').val();
          var password = $('input[type="password"][name="upass"]').val();
          $.ajax({
  
              type : "POST",
              data : {username:username,password:password},
              url  : "controller/login.php",
              beforeSend : function(){
              $('button').html('Checking...');
  
              },
              success : function(data){
                  console.log(data);
  
                   if(data.message.success == "ok"){
                      $('#results').removeClass('error');
                      $('#results').addClass('success');
                      $('#results').html('login Success, loading user data..');
                      $('button').html('Loading Profile.. i class="fa fa-spinner fa-pulse fa-1x fa-fw"&gt;&lt;/i&gt;');
                          var redirectUrl = JSON.stringify(data.redirects);
                          redirectUrl = redirectUrl.replace(/[{"":}]/g, '');
                          var url = redirectUrl.replace('redirect','');
                          setTimeout(' window.location.href = "'+ url + '"; ', 6000);
                  }else{
  
                      $('button').html("Sign in");
                      $('#results').removeClass('success');
                      $('#results').addClass('error');
                      $('#results').html(data.message.error);
                  }
              },
              error : function(xhr){
  
                  console.log('Error : ' + xhr);
              }
          });
      return false;   
      }
  </code></pre>
  
  <p>Console log results :</p>
  
  <pre><code>{"message":{"success":"ok"},"redirects":{"redirect":"seo\/index.php?route=home"}}
  </code></pre>
  
  <p>I want to be able to display the message from the json array if success is ok I will display custome message else display what is coming from response. the problem is property undefined.</p>
  
  <p>line 35 :</p>
  
  <p><code>if(data.message.success == "ok"){</code></p>