Show Json data inside an Html Form

Asked

Viewed 508 times

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);
}

1 answer

0

The problem may be in your model query. Assuming you have a model called 'Student'. Instead of $aluno= $this->aluno->select('*')->find($id); do $aluno = Aluno::find($id);.

I hope to help

  • I already made a test and the return of Json in Controller is working only that I can not pass to HTML

  • Are you able to open the modal at least? Already tried to open the modal and then put the data in the fields?

  • Yes Modal is opening normal

  • 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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.