$('form').submit(function() { alert($(this).serialize()); return false; // return true; });
what's the difference for this form submit function between return false and true ?
false
true
If you return false from the submit event, the POST form of the regular page will not.
return false , do not perform the default action for the form. return true , follow the default action for the form.
return false
return true
Also better to do
$('form').submit(function(e) { alert($(this).serialize()); e.preventDefault(); });
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/ .
bind()
"Returning false from the handler is equivalent to calling both .preventDefault () and .stopPropagation () on the event object."
return false; // cancel submit return true; // continue submit