title: jquery validate email via ajax before submitting form also via ajax
body: <p>I have a profile create form which has an email address field. I need to make sure that the email address entered by the user is in a valid format, and that it's also not already in use. For the format check, i have a simple client side validation performed by the isValidEmailAddress function which works well. For the other part where I need to check if the email address does not already exist, I do a jquery post to a controller method which returns a string "email address already in use" if the email is used by someone already..but in the code below the first "return false" is not stopping the form from submitting. Is this a jquery being asynchronous thing? </p>
  
  <pre><code>  $(document).ready(function(){
  
      $("#new_profile").submit(function(){
        var email = $("#user_email").val();    
        if(isValidEmailAddress(email)){
          jQuery.post('/profiles/validate_email', {email: email}, function(data){
            if(data.match(/in use/)){
              $(".email-check-message").html(data);
              return false;
            }
          });
        }
        else{
          $(".email-check-message").html('please enter a valid email address');
          return false;
        }
      });    
    });
  </code></pre>
  
  <p>Also, the jquery post in the above function does not seem to be working..as in i don't see the server call happening in the server log. Anyone know what's going on? Thanks.</p>