prevent page refresh on form submit code example

Example 1: html prevent submit from reloading page

<form onSubmit="return false; // Returning false stops the page from reloading">
	<button type="submit"></button>
</form>

Example 2: jquery submit refresh page stop

$("#prospects_form").submit(function(e) {
    e.preventDefault();
});

Example 3: submit() refreshes the page

<form onsubmit="return false;">Form stuff in here</form>

Example 4: why does my page reloads on form submission

//jquery method //
//preventDefault() prevents the submit button
//from performing its default task like page reload  
  $('#form').submit(function (e) {
      e.preventDefault();
  });

Tags: