1
I’m having trouble executing an ajax search with Laravel, follow the ajax code of my view:
$(document).ready(function () {
$('#enviarForm').click(function (e) {
e.preventDefault();
var form = $('#filtro').serialize();
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
}
});
$.ajax({
type: "get",
url: "{{url('/cadastro')}}",
data: form,
dataType: "json",
success: function (response) {
alert('ola');
}
});
});
});
Controller code:
if($request->ajax()){
$nome = $request['ds_paciente'];
$Pessoas=\App\Pessoas::where('ID_CD_TIPOPESSOA',1)
->where('IN_STATUS',1)
->where('NM_PESSOA', 'LIKE', '%' . $nome . '%')
->paginate(10);
return view('todosPacientes',compact('Pessoas'));
}
I’m a little lost and I’m not finding tutorials on the internet.
Do you have a mistake? Or what happens? The form
#filtro
has the fieldds_paciente
?– Leite
The mistake is that nothing happens, it just doesn’t work, the fields are correct
– André Tripode Colognesi
Post your html/Blade code as well
– MarceloBoni
tried
$request->input('ds_paciente')
– adventistaam
Bro, first if you want return using Ajax, the controller has to be: Return Response::json($Ponsulta);
– Joan Marcos