1
I have a table where the lines constantly change order, I need to record this table in the bank. Since I will no longer modify the table I click on a "Confirm Grid" button, at that moment save this table in an array within jquery, and when I want to send php click to submit in the form.
However I cannot receive this data on 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?
What you’re trying to do doesn’t exist, you can’t send an Alert echo through PHP, when you use Smarty, the output is sent through a compiled array that generates a visualization template of this compilation, what will be seen is sent in a view via an element calling
$smarty->assign('variavel', $dados)
. Note that by the layout of your view this is Smarty.– Ivan Ferrer
Here is the Smarty documentation
– Ivan Ferrer
I just used this echo to test if I was getting information from the front. It really doesn’t interest me.
– Gabriel Pereira
You need to put the correct code then PHP, so that someone can help you in this. Because it seems to me very incomplete your question.
– Ivan Ferrer