I do an Ajax check on the server, no matter what happens there, the answer is either "0" or "1", with "0" the form should not submit, my code is as follows:

$('form[name=gform]').submit(function(){ guest =$('#guest').val(); $.ajax({ url: "do.php", type: "POST", async: false, data: { action: 'guest', guest: guest }, success: function(data) { if (data==0) { return false; } } }); }); 

Unfortunately, the submit occurs anyway, how to prevent it? As you can see, return false did not save me.

  • Did you understand what you wrote? How do you get the server response without a submission? 0 - it should also come from the server ... Generally dig in the other direction. - Fucking Babay
  • I get a (CORRECT) response from the server. The question is that the form has just been submitted with return false. - Smash

1 answer 1

try:

 $('form[name=gform]').submit(function(e){ e.preventDefault(); ... 

or

  ... $.ajax({...}); return false; }); 

because You do not quite understand the principle of how a success callback works

  • Yes, I removed the submit at all, did not approach the situation correctly, I had to alter a little logic, well, who does not make mistakes? - Smash