0
I am trying to implement a page where the values of a table registered in a system database can be changed.
When selecting the names of the people listed, I call the function ola
through the onchange
, which is working perfectly, but when trying to update the values registered in inputs
of form
, can’t.
This is my job:
function ola(val){
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
})
$.ajax({
url:'editarInstalador',
data:{pid:val},
type:"POST",
data:{pid:val},
success:function(data){
},
error:function(data){
},
});
return false;
}
My route:
Route::post('editarInstalador', 'instaladorController@edit');
The function in the controller:
public function edit()
{
$json = array();
$idPessoa = request("pid");
$instaladorDados = DB::select("SELECT * FROM public.tblInstalador WHERE inst_id = {$idPessoa}");
foreach ($instaladorDados as $var) {
$json[]= array(
'nomee' => $var->inst_razaosocial,
'nomeFantasia' => $var->inst_nomefantasia,
'cnpj' => $var->inst_cnpj,
);
}
return response()->json($json);
}
I’m getting the perfect call controller
, do the research in the bank and as an answer I have in the response
browser:
[{"nomee":"nomeCadastrado","nomeFantasia":"daniel franca","cnpj":"cnpj cadastrado"}]
My problem is that first, at $.ajax
where I call the route, he literally always enters the error
, never gets into the success
.
My second question is: how can I pass this answer to the view
and fill in the inputs
with this data?
Thanks for the help friend, the route issue worked perfectly and now it enters the Success correctly. I got a response on the console: [{... }] 0: {name: "filename", fileName: "Filename", cnpj: "cnpj registered"} length: 1 proto: Array(0) Please give me an example of how to play these values for inputs? Again thank you for your help
– Daniel França
I decided using the code: Success:Function(data){ $("#test"). attr({value:data[0].nomee}); }, Again thank you for your attention. Att.
– Daniel França
I just edited the answer, but that’s exactly what you commented
– Darlei Fernando Zillmer