how to submit form with jquery code example

Example 1: jquery submit form

// It is simply
$('form').submit();

// However, you're most likely wanting to operate on the form data
// So you will have to do something like the following...
$('form').submit(function(e){
	// Stop the form submitting
  	e.preventDefault();
  	// Do whatever it is you wish to do
  	//...
  	// Now submit it 
    // Don't use $(this).submit() FFS!
  	// You'll never leave this function & smash the call stack! :D
  	e.currentTarget.submit();
});

Example 2: when a form is subbmited jquery

$("#myform").submit(function(e) {
 })

Example 3: jquery on form submit call function

$(document).ready(function() {
  $("your form selector here").submit(function() {


    // do the extra stuff here
    $.ajax({
     type: "POST",
      url: "mail.php",
      data: $(this).serialize(),
      success: function() {
        $('.simple-sucess').fadeIn(100).show();
        $('.contact_form').fadeOut(100).hide();
        $('.simple_error').fadeOut(100).hide();

       }
    })

  })
})

Example 4: ajax post form listener button

$("button").click(function(e) {
    e.preventDefault();
    $.ajax({
        type: "POST",
        url: "/pages/test/",
        data: { 
            id: $(this).val(), // < note use of 'this' here
            access_token: $("#access_token").val() 
        },
        success: function(result) {
            alert('ok');
        },
        error: function(result) {
            alert('error');
        }
    });
});

Tags:

Html Example