I have a simple form and I am sending it to the controller via Ajax, but my problem is that after clicking on the submit button it does not call the Ajax request in my Jquery and it already leads directly to this error. p>
Ihaveanothercontrollerandcopiedtheentireprocessbychangingonlytheinputsandfields
JavaScriptcodethatthesystemshouldpassaftersubmits
jQuery("#formRecebimento").submit(function(){
var dados = jQuery( this ).serialize();
jQuery.ajax({
type: 'post',
url: 'recebimentos/cadastrar',
data: dados,
beforeSend: function(xhr){xhr.setRequestHeader('X-CSRF-TOKEN', $("#token").attr('content'));},
success: function(data) {
if($.isEmptyObject(data.error)){
alert(data.id);
$('#modalAddCliente').modal('hide');
}else{
printErrorMsg(data.error);
}
}
});
return false;
});
But he does not even get to that part of the code!
PS: IN ANOTHER CONTROLLER I MOUNTED THE SAME WAY AND WORKED CORRECTLY
ROUTES
$this->group(['prefix' => 'recebimentos'], function(){
$this->post('cadastrar', 'RecebimentoController@store');
$this->post('atualizar', 'RecebimentoController@update');
$this->post('detelar', 'RecebimentoController@destroy');
$this->get('/', 'RecebimentoController@index');
});
PS CONTROLLER: THE INDEX IS WORKING NORMALLY AND I LEAVE THE STORE COMMENTED TO FIND WHERE THE ERROR IS AND IT DOES NOT ARRIVE AT MY CONTROLLER
public function store(Request $request){ /*
$validator = Validator::make($request->all(), [
'data_receb' => 'required|date|after:start_date',
'valor' => 'required',
'cliente_id' => 'required',
'plano_contas' => 'required|max:100',
]);
if ($validator->passes()) {
$recebimento = Recebimento::create($request->all());
return response()->json($recebimento);
}
return response()->json(['error'=>$validator->errors()->all()]); */
return "asefa";
}
PART OF THE FORM DEFINITION
<form id="formRecebimento" method="post">
<input type="hidden" name="_token" id="token" value="{{ csrf_token() }}">
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label for="data_receb">Data do Recebimento*</label>
<input type="date" class="form-control data_receb" id="data_receb" name="data_receb" >
</div>
</div>
GLOBAL SCRIPT PS: I HAVE A JS FILE FOR EACH CONTROLLER
$.ajaxSetup({
headers: {
'X-XSRF-Token': $('meta[name="_token"]').attr('content')
}
});