title: Login validation not working on HTML using JSON and PHP
body: <p>I am making a login form on HTML using JSON and PHP but all of the <code>if</code> statements on success are not working but the <code>beforeSend</code> and <code>error</code> is working. Can you help me check my mistakes?</p>
  
  <p>I dont know know what is wrong with the function on success. The alerts are not popping up. For example <code>response.success == true</code> is supposed to pop up ' You are successfully logged in... '</p>
  
  <pre><code>&lt;script&gt;
  $(document).ready(function(){
      $('#loginForm').on('submit',function(e){
  
          var myForm = new FormData($(this)[0]);
  
          $.ajax({
              type:'POST',
              url: 'connections/login.php',
              data : new FormData($(this)[0]),
              cache: false,
              contentType:false,
              processData: false,
              beforeSend: function(){
                  $("div#divLoading").show();
              },
              success: function(response){
                  $("div#divLoading").hide();
                  console.log(response);
                  if(response.success == true)
                  {
                      alert(' You are successfully logged in... ')
                  }
  
                  else if( response.success == false ){
                      alert('please enter a correct email &amp; password');
                  }
                  else{
                      if(response.matric){
                          alert('email is wrong');
                      }
                      if(response.password){
                          alert('password is wrong');
                      }
                  }
              },
              error: function(data){
                  alert('error');
                  $("div#divLoading").hide();
              }
          });
      return false;
      });
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>Here is my PHP:</p>
  
  <pre><code>&lt;?php
  require_once('connect.php');
  
  session_start();
  
  header('Content-Type: application/json');
  if (!empty($_POST['matric']))
  {
  $matric=$_POST['matric'];
  $password=$_POST['password'];
  
  
  
  $pass= $dbh-&gt;prepare("SELECT * FROM users WHERE matric=:matric AND password=:password");
  $pass-&gt;bindParam(':matric', $matric);
  $pass-&gt;bindParam(':password', $password);
  $pass-&gt;execute();
  if($pass-&gt;fetch(PDO::FETCH_NUM) &gt; 0)
  {
      $_SESSION['matric']=$matric;
      $response = array(
      'success' =&gt; true,
      'message' =&gt; 'Login successful');
  }
  else
  {
      $response = array(
      'success' =&gt; false,
      'message' =&gt; 'Login fail');
  }
  
  }
  
  echo json_encode($response);
  echo json_encode($_POST);
  
  ?&gt;
  </code></pre>