0

How do I get all the data from the form?

$.ajax({
  url: '/wp-admin/admin-ajax.php',
  method: 'post',
  data: {
    action: 'form_handler_subscribtion',
     // 
  },
  success: function ( success ) {

  },
  fail: function( fail) {

  }
});

I can get the data by specifying each field manually, but I would like to get it automatically. Can you tell me how to do this?

wasterel
  • 43
  • 5

2 Answers2

0

You can use .serialize()
Official doc
Example:

var data = $("#idform").serialize(); 
$.ajax({
  url: '/wp-admin/admin-ajax.php',
  method: 'post',
  data: data,
  success: function ( success ) {

  },
  fail: function( fail) {

  }
});
Simone Rossaini
  • 8,115
  • 1
  • 13
  • 34
0

Try this

  $.ajax({
      url: '/wp-admin/admin-ajax.php',
      method: 'post',
      data: {
        action: $('YOUR FORM ID').serialize(),
         // 
      },
      success: function ( success ) {
    
      },
      fail: function( fail) {
    
      }
    });
WiatroBosy
  • 1,076
  • 1
  • 6
  • 17