Home / Tips / Programming languages / Scripting languages / JavaScript / How to get POST data including the submitted button when submitting form in jQuery

How to get POST data including the submitted button when submitting form in jQuery

jQuery
 
jQuery
  • Currently 5 out of 5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Rating: 5/5 (1 votes cast)

Thank you for rating!

You have already rated this page, you can only rate it once!

Your rating has been changed, thanks for rating!

Log in or create a user account to rate this page.


The following example demonstrates how to get POST data of the entire form including POST data of the submitted button.

jQuery( 'form input[type=submit]' ).click( function( event ) {
  event.preventDefault();
  currentForm = jQuery( this ).parents( 'form' );
  currentFormPostArray = currentForm.serializeArray();
  currentFormPostArray.push({
    name: jQuery( this ).attr( 'name' ),
    value: jQuery( this ).attr( 'value' )
  });
  jQuery.post( currentForm.attr( 'action' ), jQuery.param( currentFormPostArray ) ).done( function( data ) {
    //code to work with received data
  });
});

 

Read also

jQuery for beginners: selectors

jQuery for beginners: selectors

jQuery for beginners: AJAX

jQuery for beginners: AJAX

jQuery for JavaScript

jQuery for JavaScript

jQuery UI. Widgets. Dialog (Windows)

jQuery UI. Widgets. Dialog (Windows)

Post comment

basicuse.net
html5_css
106160485398655174790

Quick navigation

General navigation