title: "Continue" a PHP redirect with AJAX?
body: <p>I have an HTML form that is processed via PHP, and it's a simple login script. This works fine, but I want to catch the error with AJAX. Basically, if the PHP function to check the login returns false, it should write that error onto the DOM via jQuery. However, if I catch the form submission with AJAX, it will stop the PHP file from doing the redirect. I want to stop the form from redirecting only if the PHP file returns false. Any help would be much appreciated. Here's some code to illustrate what I'm talking about:</p>
  
  <p><code>controller_login.js</code></p>
  
  <pre><code>$(document).ready(function(){
  
  $('form.loginSubmit').on('submit',function(){
  
  
      var that = $(this),
          url=that.attr('action'),
          type=that.attr('method'),
          data={};
  
      that.find('[name]').each(function(index,value){ 
          var that=$(this), 
              name=that.attr('name'); 
              value=that.val(); 
              data[name]=value;
      });
  
  
      $.ajax({
          url: url,
          type: type,
          data: data,
          success: function(response){
              errorHandle(response);
  
          }
  
  
      });
  
  return false;
  
  });
  
  
  });
  
  function errorHandle(error)
  {
      console.log(error);
  }
  </code></pre>
  
  <p>This is the file that will eventually modify the DOM if there is a PHP error. For now, it just logs. </p>
  
  <p><code>checkLogin.php</code></p>
  
  <pre><code>if($verifySqlRequest==1){
      session_register("loginUsername");
      session_register("loginPassword");
      header("location:http://localhost/asd/dashboard.html");
      echo "login success!";  
  }
  else{
      echo "Wrong user name or password...";
  }
  </code></pre>
  
  <p>This is just a snippet of the login authentication, but essentially I want that last echo to be communicated to <code>controller_login.js</code>, but it should continue the redirect if the login is successfully authenticated. Any help would be much appreciated!, thanks!</p>