title: ajax call returns true after returning false and form submits
body: <p>I'm having a function that returns true or false to submit a form via ajax</p>
  
  <pre><code>&lt;form method="post" onsubmit="return validate()"&gt;
    &lt;input type="text" name="user" id="user"&gt;
  &lt;/form&gt;
  
  function validate(){
    var n = $("#user").val();
    if(n.length&lt;2){           
          return false;
      }
      else{
          $.ajax({
              url: 'ajax/checkuser.php',
              global: false,
              type: 'POST',
              data: {user:n},
              async: false, //blocks window close
              success: function(data) {
                  if(data.trim().indexOf('exists')&gt;-1){
                      alert('user exists);
                      return false;
                  }
                  else if(data.trim().indexOf('ok')&gt;-1){
                      return true;
                  }
              }
          });
      }
  }
  </code></pre>
  
  <p>when I press ESC and check the Net via console i find the ajax request returning 'exists' and the alert of 'user exists' is fired but the form gets submitted while it shouldn't submit</p>
  
  <p><a href="https://i.stack.imgur.com/DZDVo.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DZDVo.jpg" alt="enter image description here"></a></p>