Good afternoon, I have this code:
<?php foreach ($resultado as $row) { ?>
<tr>
<td class="seis"><?php echo $row['seis']; ?></td>
<td class="ban"><?php echo $row['ban']; ?></td>
<td name="bon"><?php echo $row['bon']; ?></td>
<td name="qntd"><?php echo $row['quantidade']; ?></td>
<td name="pre"><?php echo "R$ " . $row['preco']; ?></td>
<td name="ven"><?php echo $row['Vendedor']; ?></td>
<td class="text-right">
<input name="comprar" id="comprar" value="Comprar" class="btn btn-success" type="submit"></input>
</td>
</tr>
<?php } ?>
It makes a table for each column in the DB. I need to send this information (performing a POST) of what is between <td>
. I tried with this code:
<script>
$(document).ready(function () {
// No click do botão de submit
$('#comprar').click(function () {
// Recebe os dados do formulário
var valorTd = $('.seis').text();
// Envia a requisição ajax
$.ajax({
url: "ajax/recebe_pedido.php", // Arquivo php que vai receber os dados
data: { // Recebe os dados das td´s e passa em um json
valorTd: valorTd,
},
global: false,
type: "POST",
contentType: "application/x-www-form-urlencoded;charset=utf-8",
dataType: "html",
success: function (data) { // se tudo der certo mostra essa mensagem
alert('Requisição realizada com sucesso!');
},
}).responseText;
});
});
</script>
But when you click the buy button, all <td>
is being sent, it's supposed to send according to the column that I clicked the buy / p>
Example: valorTd: 498401 498406 547874 547874 547874 547874 547874 547874 547874 547874