1
I have a Grid with the edit button when I click on it it accesses the Controller and brings the data in a Json and "Theoretically" was to return this data in a Modal.
When I type Url .... show/(ID) the Json data appears but I am unable to make this data appear in the Modal Form.
Follows the Code
HTML (Button and Inputs where the data was to appear)
<a href="#" onclick="GetAlunoDetails('{{$valor->id}}')" data-target="#editModal" data-toggle="modal">{{ $valor->nome }}</a>
<input type="text" class="form-control" id='nometeste' name="nometeste" value="">
<input type="text" class="form-control" id='idteste' name="idteste" value="">
<input type="hidden" id="hidden_user_id">
JS
function GetAlunoDetails(id) {
$("#hidden_user_id").val(id);
$.get("/.../alunos/show/"+id, {
},
function (data) {
// PARSE json data
var aluno = JSON.parse(data);
// Assing existing values to the modal popup fields
$("#nometeste").val(aluno.nome);
$("#idteste").val(aluno.id);
}
);
// Open modal popup
$("#editModal").modal("modal");
}
CONTROLLER
public function show($id)
{
//Pegando os valores para preencher a tabela
$aluno= $this->aluno
->select('*')
->find($id);
return response()->json($aluno);
}
I already made a test and the return of Json in Controller is working only that I can not pass to HTML
– Shaolin Fantastic
Are you able to open the modal at least? Already tried to open the modal and then put the data in the fields?
– lstonon
Yes Modal is opening normal
– Shaolin Fantastic
Try to open the modal inside the return function. This call is asynchronous and so may have the delay to go to the server and come back, causing this problem.
– lstonon