I am creating a system and at a certain time the user can register the measurements of a person. To do so, I would like to redeem the ID and Name in the people table, so they are displayed in the modal, but I'm not having success, even trying in different ways. I'm trying to use Ajax, since to include and exclude information I've already used this tool successfully.
My student query table is generated with the following actions:
$tabela .= "\n <td class='grid' style='width:8%' align='center'>";
$tabela .= " <button class='btn btn-warning' onclick='_editar($codigo)' type='button'><span class='glyphicon glyphicon-edit'></span></button>";
$tabela .= "</td>";
$tabela .= "\n <td class='grid' style='width:8%' align='center'>";
$tabela .= " <button class='btn btn-danger' onclick='_excluir($codigo)' type='button'><span class='glyphicon glyphicon-remove-circle'></span></button>";
$tabela .= "</td>";
Where the (id) code is passed as a parameter to the edit exclusion methods.
No_edit I have:
function _editar(varFiltro){
$('#txtID').val(varFiltro);
$.ajax({
url: 'index.php?controle=Aluno&acao=editar',
dataType: 'html',
type: 'POST',
data: {
idAluno: varFiltro
},
dataType:"json",
success: function(data) {
$('#txtID').val(data["id"]);
$('#txtNome').val(data["nome"]);
}
});
$('#frmModal').modal('show');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
Andinmycontrol:
publicfunctioneditar(){$this->modelo('Aluno');$idAluno=$_POST['idAluno'];$sql="select id, nome from aluno where id = $idAluno";
$result = $this->nome->pesquisar($sql);
$arr = Array();
$html = "";
if($result){
while($consulta = mysql_fetch_assoc($result)){
$arr['id'] = consulta['id'];
$arr['nome'] = consulta['nome'];
}
}
die(json_encode($arr));
}
And the view looks like this:
<div class="modal fade" id="frmModal" tabindex="-1" role="dialog" aria-labelledby="modalLabel" aria-hidden="true" style='max-height: 100%; overflow-y: auto;'>
<div class="modal-dialog modal-dialog-centered" role="document" style="max-width: 900px;">
<div class="modal-content">
<div class="modal-header">
<table style="width: 100%;">
<tr width="100%">
<td width="90%">
<h3 class="modal-title" id="modalLabel">Cadastro de Medidas</h3>
</td>
<td width="10%">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true"><h3>×</h3></span>
</button>
</td>
</tr>
</table>
</div>
<form id="medida" method="post">
<div class="modal-body">
<table class="table table-striped table-bordered table-hover" style="width:100%">
<tr>
<!-- IDENTIFICADOR -->
<td class="borda_transparente" style='width:20%'>
<div style="width:95%;" class="selectpicker">
<label for="txtID">Nº ID</label>
</div>
<div style="margin-bottom: 10px; width:60%" class="selectpicker">
<input class="form-control" type="text" name='txtID' id="txtID" disabled/>
</div>
</td>
<!-- Título do Menu -->
<td class="borda_transparente" style='width:100%'>
<div style="width:95%;" class="selectpicker">
<label for="txtNome">Nome</label>
</div>
<div style="margin-bottom: 10px; width:95%" class="selectpicker">
<input class="form-control" type="text" name='txtNome' id="txtNome" maxlength="40"/>
</div>
</td>
</tr>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-success" aria-label="Left Align" onclick="_gravar();"><span class="glyphicon glyphicon-ok" aria-hidden="true" style="margin-right:5px"></span>Gravar</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
</div>
</form>
<div id="mensagemModal"></div>
</div>
</div>
</div>
Only the ID is populated, depending on the image, the name remains blank: