What is the difference between fidelity or falsehood?

$('form').submit(function() { alert($(this).serialize()); return false; // return true; }); 

what's the difference for this form submit function between return false and true ?

+8
javascript jquery html jquery-ui
source share
4 answers

If you return false from the submit event, the POST form of the regular page will not.

+8
source share

return false , do not perform the default action for the form. return true , follow the default action for the form.


Also better to do

 $('form').submit(function(e) { alert($(this).serialize()); e.preventDefault(); }); 
+3
source share

As mentioned, returning false stops the event from bubbling up. If you want complete information, check out the API documentation for bind() : http://api.jquery.com/bind/ .

"Returning false from the handler is equivalent to calling both .preventDefault () and .stopPropagation () on the event object."

+2
source share
 return false; // cancel submit return true; // continue submit 
+1
source share

All Articles