Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what's the difference of return true or false here?

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

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

like image 717
Leem Avatar asked May 12 '11 12:05

Leem


2 Answers

If you return false from the submit event, the normal page form POST will not occur.

like image 119
Matthew Abbott Avatar answered Sep 29 '22 13:09

Matthew Abbott


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();
});
like image 39
stealthyninja Avatar answered Sep 29 '22 11:09

stealthyninja