I can not do the ajax query in Laravel5.5.
Inquiry Form:
<form action="ConsultaEmpresa" method="get" name="FormConsultaEmpresa" id="FormConsultaEmpresa">
{{ csrf_field() }}
<input type="date" style="width: 30%;" class="form-control" name="Data_Inicial" id="Data_Inicial">
<button class="btn btn-success" style="margin-left: 10px;" id="Consulta_Empresa" type="submit">Pesquisar</button>
</form>
JS query (Ajax for the query):
jQuery(document).ready(function($) {
$("#FormConsultaEmpresa").submit(function (e) {
e.preventDefault();
$.ajax({
type: "get",
url: "/ConsultaEmpresa/ " + $('#Data_Inicial').attr("value"),
dataType: 'json',
headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
data : $(this).serialize(),
success: function (Consulta) {
Consulta.responseJSON;
console.log(Consulta);
},complete() {
console.log("complete");
}
});
});
});
Controller that returns the Ajax query
public function ConsultaAjax(Request $Data_Inicial)
{
/*
$date = explode("/", $Data_Inicial);
$dateBanco = $date[2]."/" . $date[1] . "/" . $date[0];*/
$Consulta = DB::table('empresas')->where([ ['Empresa_Dtinicioacesso', '=', $dateBanco] ])->get();
return Response::json($Consulta);
}
My query path
Route::get('/ConsultaEmpresa/{Data_Inicial}', ['uses' => 'EmpresaController@ConsultaAjax']);
This message appears in the log (Insert element) when the request ends.
XHR finished loading: POST " link "