I'm trying to implement a page where the values of a table can be changed in the database of a system.
When I select the name of the people listed, I call the function ola
through onchange
, which is working perfectly, but when trying to update the values registered in inputs
of form
, I can not. / p>
This is my role:
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 am able to perfectly call controller
, do the search in the database and as an answer I have in response
of the browser:
[{"nomee":"nomeCadastrado","nomeFantasia":"daniel franca","cnpj":"cnpj cadastrado"}]
My problem is that first of all, in% with% of where I call the route, it literally always enters $.ajax
, never enters error
.
My second question is: how can I pass this response to success
and fill view
with this data?