Ajax实时表单验证

I am using Ajax for signup form with jquery blur, it is validating , but when i click on submit form data gets save in db i need not to save data on submit untill user not correct the fields text how can i avoid this problem ?

$(document).ready(function () {

$('#username').blur(function() {
var username = $('#username').val();
if (window.XMLHttpRequest)
  {
    xmlhttp=new XMLHttpRequest();
  }
  else
      {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      xmlhttp.onreadystatechange=function(){
          if (xmlhttp.readyState==4 && xmlhttp.status==200)
                {
                if(username !=""){
                //$('#wait').removeClass('loading');

                    if(xmlhttp.responseText.match(/Space/g)){ 
                        $('#usernameErr').css('display','none');
                        $("#valid_username").html('User name is not valid');
                        $('#wait').addClass('loading'); 
                        return false;       
                    }
                    if(xmlhttp.responseText.match(/No/g)){ 
                        $('#usernameErr').css('display','none');
                        $("#valid_username").html('');
                        }
                    }
                }
          }
         // $('#wait').addClass('loading');
          xmlhttp.open("GET","process_signup.php?name="+username,true);
          xmlhttp.send();             

});

You need to prevent the form from submitting until the errors are cleared. You can do something like this:

$('#my-form').submit(function(e){
    if( checkFormForErrors() ) {
        e.preventDefault();
    }
}

Then just build a checkFormForErrors function and have it return true if there are any errors with the form.

However, keep in mind that you should always check for errors on the server side as well. Never assume the user is giving you good input. You will get hacked if you don't check the input.