title: How to handle an error on ajax login form?
body: <p>I have several login forms that use ajax, but now when information is wrong the page just refreshes. I want to catch some keyword/variable from my php, right now I am echoing 'error', and I want some alert on the page with no refresh. Here's my current js. When I submit, a login object is created and then the login method performed, if successful it redirects to a dashboard if not it echos 'error' and then how can I accomplish what I need with javascript? </p>
  
  <pre><code>&lt;script&gt;
  $('#doctor_login').on("submit", function(e){
  
  
  frmReg = document.getElementById("doctor_login");
  
  
      if(frmReg.user_name.value == "")     { alert("&lt;?php echo _USERNAME_EMPTY_ALERT; ?&gt;"); frmReg.user_name.focus(); return false;        
      }else if(frmReg.password.value == ""){ alert("&lt;?php echo _PASSWORD_IS_EMPTY; ?&gt;"); frmReg.password.focus(); return false;        
      }else{
              $.ajax({
  
      type:'POST',
      url: '../page/handler/handler_ajax_login.php',
      data: $(this).serialize()
      }
  
  
      });
      }
  });
  </code></pre>
  
  <p></p>