Reputation: 18318
$('form').submit(function() {
alert($(this).serialize());
return false; // return true;
});
what's the difference for this form submission function between return false
and true
?
Upvotes: 8
Views: 12946
Reputation: 71
As already mentioned, returning false stops the event from "bubbling up". If you want the full details, take a look at the API documentation for bind()
: http://api.jquery.com/bind/.
"Returning false from a handler is equivalent to calling both .preventDefault() and .stopPropagation() on the event object."
Upvotes: 2
Reputation: 10371
return false
, don't do the form's default action. return true
, do the form's default action.
It's also better to do
$('form').submit(function(e) {
alert($(this).serialize());
e.preventDefault();
});
Upvotes: 3
Reputation: 61599
If you return false
from the submit event, the normal page form POST will not occur.
Upvotes: 8