How to send input values type "hidden" ajax?

1

The question is the following one, I am elaborating a project of degree I am doing sending of values stored in "hidden" inputs, but as they are different forms I want to try to make a single shipment, which sends me only the data of the form of the which was the action.

FORMS

<form method="post" data-toggle="GenerateTable">
   <input type="hidden" value="<?php echo "01";?>" data-id="tableGenID">
   <input type="hidden" value="<?php echo "colaborators";?>" data-role="tableGenType">
         <button type="submit" class="btn btn-primary p-1" data-toggle="modal" data-target="#EditModalCenter">
              <i class="material-icons table-icon-options">
                   edit
              </i>
          </button>
</form>

<form method="post" data-toggle="GenerateTable">
   <input type="hidden" value="<?php echo "01";?>" data-id="tableGenID">
   <input type="hidden" value="<?php echo "inventory";?>" data-role="tableGenType">
      <button type="submit" class="btn btn-primary p-1" data-toggle="modal" data-target="#EditModalCenter">
           <i class="material-icons table-icon-options">
                 edit
            </i>
       </button>
</form>

Send php document.

$('form[data-toggle="GenerateTable"]').submit(function(){
          $.post('../../libs/TableGenerator.php',
              {
                tableId:      $('input[data-id]').val(),
                tableType:    $('input[data-role]').val(),
              },
              function(Table_answer){
                $('#ContentTableGenerator').append(
                  $('#ContentTableGenerator').add(Table_answer.GenerateTable)
                );
              }, 'json');
              return false;
        });

My problem is that I only take the values of the first Input "hidden" in the send;

    
asked by Brayan Rodriguez 02.09.2018 в 19:42
source

2 answers

0

You could try making an arrangement and send it as an arrangement

var Arreglo=new Array();
$("input[type='hidden']").each(function(){
Arreglo.push($(this).attr("data-id"));
});
console.log(Arreglo);

Or go through each form to send only the data of that form

I understand that you can only send one post at a time; so you can try to group everything in the same form

Greetings:)

    
answered by 02.09.2018 в 20:25
0

That would be a good option, but there is no property like for example the [data-toggle] that allows only take the values of the form of which I am making the shipment, or only use different IDs?

    
answered by 03.09.2018 в 19:55