I've created a system where it displays data from a mysql
table via the datable
plugin. One of the data is a modal. The javascript code takes data-ref
, which contains id
. This id
will be used in future% queries.
Doubt : When more than one row is generated, ajax always returns the id of the first row, not the id of the row you click. I want to know how to return mysql
(which is in a id
attribute) of the specified line.
This is javascript code that gets "id" and fires ajax:
$('#verpedido').on('show.bs.modal', function (e) {
let id_pedido = $("#detalha").attr('data-ref');
$.ajax({
url: 'http://notasfiscais-ipc.stackstaging.com/edita.php',
data: {id: id_pedido},
type: 'POST',
success: function(response){
$('#teste').empty();
$('#teste').html(response);
}
});
});
This is the HTML of the table:
<td class="sorting_1">34592</td><td>005_17</td><td>CLIENTE 01</td><td>2017-04-12</td><td></td><td></td><td></td><td><a href="#ver_pedido" data-toggle="modal" data-target="#verpedido" data-ref="34592" id="detalha" class="btn btn-primary"><i class="fa fa-plus" aria-hidden="true"></i></a> </td></tr>
<tr role="row" class="even"><td class="sorting_1">35194</td><td>2689</td><td>CLIENTE 02</td><td>2017-05-16</td><td></td><td></td><td></td><td><a href="#ver_pedido" data-toggle="modal" data-target="#verpedido" data-ref="35194" id="detalha" class="btn btn-primary"><i class="fa fa-plus" aria-hidden="true"></i></a> </td></tr>
</tbody>'