I have a form sent by ajax but it does not save the information in the DB when I activate e.preventDefault (); if I mention it if you save it.
EL Ajax is:
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$("#enviar").click(function(e){
e.preventDefault();
var codigo = $('#codigo').val();
var tipo = $('#tipo').val();
var ip = $('#ip').val();
$.ajax({
type:'POST',
url: 'control',
data:{
codigo: codigo,
tipo: tipo,
ip: ip},
success: function(data){
console.log(data);
}
});
});
The driver is:
public function store(Request $request)
{
//dd($request->All());
$control = new Control();
$control->identification = $request->codigo;
$control->type = $request->tipo;
$control->date = date("Y/m/d");
$control->time = date("h:i:s");
$control->ip = $request->ip;
$control->save();
return response()->json(['success'=>'Got Simple Ajax Request.']);
}
The routes are:
Route::get('/control', 'ControlController@index');
Route::post('/control/store', 'ControlController@store');
I am using version 5.7 of laravel, I do not know if any books are missing, try the tutorials that I see on youtube and they are the same ones that I have always used.