I need to send the value of a table that is in a modal to the server and then open another modal using the information from the first table, however the variable always returns me null, I already tried to use ajax however it did not work, it does nothing and gives me no feedback, follow the code to better understand the problem:
MODAL THAT PASSES THE INFORMATION:
<form id="visualizarAparelhos" name="visualizarAparelhos" method="post" enctype="multipart/form-data">
<table class="table table">
<thead>
<tr>
<th>Número</th>
<th>Nome</th>
<tbody>
<?php
$con = mysqli_connect("localhost","roberto","","manutencao");
$query = ("select max(id) from aparelhos");
$max = mysqli_query($con,$query);
$fetch = mysqli_fetch_row($max);
$max = $fetch[0];
$i = 0;
while ($i != $max)
{
$i++;
$con = mysqli_connect("localhost","roberto","","manutencao");
$query = ("select id,nome from aparelhos where id = ".$i." ");
$aparelho = mysqli_query($con,$query);
$fetch = mysqli_fetch_row($aparelho);
$id = $fetch[0];
$nome = $fetch[1];
print "<tr>";
// PRECISO PASSAR O IdAparelho para o segundo modal
print "<td id='IdAparelho' value='".$id."'><button type='button' class='btn btn-primary' data-toggle='modal' data-target='#modalVisualizarComponentes'>".$id."</button></td>";
print "<td><strong>".$nome."</strong></td>";
print "</tr>";
}
?>
</tbody>
</tr>
</thead>
</table>
</form>
MODAL RECEIVING INFORMATION:
<div class="modal-body">
<table class="table table-striped">
<tr>
<th>Sequencial</th>
<th>Código</th>
<th>Nome</th>
<th>Entrada</th>
<th>Saída</th>
<th>Quantidade F</th>
<th>Quantidade M</th>
<th>Quantidade G</th>
<th>Quantidade GG</th>
<th>Total</th>
<tbody>
<?php
$con = mysqli_connect("localhost","roberto","","manutencao");
// VOU USAR A INFORMAÇÃO DO OUTRO MODAL AQUI
$query = ("select id_principal from componentes where id_secundario = ".$_POST['IdAparelho']." ");
$ids = mysqli_query($con,$query);
while ($linha = mysqli_fetch_array($ids))
{
$con = mysqli_connect("localhost","roberto","","manutencao");
$query = ("select * from componentes where id_principal = ".$linha[0]." ");
$componentes = mysqli_query($con,$query);
$resultado = mysqli_fetch_row($componentes);
$id_componente = $resultado[1];
$codigo = $resultado[2];
$nome = $resultado[3];
$entrada = $resultado[4];
$saida = $resultado[5];
$f = $resultado[6];
$m = $resultado[7];
$g = $resultado[8];
$gg = $resultado[9];
$total = ($f + $m + $g + $gg);
print "<tr>";
print "<td><strong>".$id_componente."</strong></td>";
print "<td><strong>".$codigo."</strong></td>";
print "<td><strong>".$nome."</strong></td>";
print "<td><strong>".$entrada."</strong></td>";
print "<td><strong>".$saida."</strong></td>";
print "<td><strong>".$f."</strong></td>";
print "<td><strong>".$m."</strong></td>";
print "<td><strong>".$g."</strong></td>";
print "<td><strong>".$gg."</strong></td>";
print "<td><strong>".$total."</strong></td>";
print "</tr>";
}
?>
</tbody>
</tr>
</thead>
</table>
</div>
MY AJAX:
$(function () {
$("#visualizarAparelhos").submit(function (e) {
e.preventDefault();
var FormData = $($this).serialize();
$.ajax({
type: "POST",
url: "administrador.php",
data: FormData
}).done(function (data) {
alert(data);
});
return false;
alert("Não funfou!!!");
});
});