I have a table where the rows constantly change order, I need to write this table to the bank. From the moment I will no longer modify the table I click on a "Confirm Grid" button, at that time saved that table in an array inside the jquery, and when I want to send pro php clico to submit in the form.
But I can not get this data in the back, I get a "Notice: Undefined index: pilots"
html:
<table id="tabelaPilotos" class="table table-striped">
<tbody>
{foreach from=$pilotos item=row}
<tr>
<td>
{$row.numero}
</td>
<td>
{$row.nome}
</td>
</tr>
{/foreach}
</tbody>
</table>
<input type="button" id="add" value="Confirmar Grid" >
<form name="form_insert" method="post" id="form_insert">
<fieldset style="display: none;"></fieldset>
<label>
<input type="submit" id="confirmar" name="confirmar" value="Cadastrar grid" />
</label>
</form>
jQuery:
var pilotos = [];
$("#add").click(function () {
$('#tabelaPilotos tbody tr').each(function () {
var colunas = $(this).children();
var piloto = {
'numero': $(colunas[0]).text(),
'nome': $(colunas[1]).text()
};
pilotos.push(piloto);
});
console.info(pilotos[0]);
});
$("#form_insert").submit(function () {
$.ajax({
type: 'POST',
cache: false,
data: pilotos,
dataType: "json",
url: 'cad_corrida.php',
success: function (msg) {
alert(msg);
}
});
});
php:
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$pilotosarray = $_POST["pilotos"];
echo "<script>alert('$pilotosarray')</script>";
}
How to recover this array?