Skip to main content
added 128 characters in body
Source Link
Felix Kling
  • 820.1k
  • 181
  • 1.1k
  • 1.2k

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. This is done with event.preventDefault [docs]. The return false inside the Ajax callback will have no effect, as the functionevent handler 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(); } }); } }); 

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(); } }); } }); 

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. This is done with event.preventDefault [docs]. The return false inside the Ajax callback will have no effect, as the event handler 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(); } }); } }); 
Source Link
Felix Kling
  • 820.1k
  • 181
  • 1.1k
  • 1.2k

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(); } }); } });