I suggest you bind the event handler to the `submit` event of the form:
$('#login2').submit(function(event) {
event.preventDefault();
//...
});
You have to prevent the default action for the event, which is submitting the form. The `return false` inside the Ajax callback will have no effect, as the function returns *before* the response was received.
If you do this, you have to set some kind of flag to see in which state of the process you are:
var nameAvailable = false;
$('#login2').submit(function(event) {
if(!nameAvailable) {
event.preventDefault(); // don't submit form
//...
$.ajax({
success: function() {
// if name available
nameAvailable = true;
$('#login2').submit();
}
});
}
});