I am having the famous error 419, which for a certain moment I managed to solve, but after restarting the server, it stopped working.
Route:
Route::post('ajax/Register', 'Ajax@Register');
Controller:
public static function Register()
{
$input = request()->all();
return $input;
}
TARGET TAG:
<meta name="_token" content="{{ csrf_token() }}">
JS:
var _token = $('meta[name="_token"]').attr('content');
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': _token
}
});
$('#formRegister').submit(function() {
$.ajax({
url: 'ajax/Register',
type: 'POST',
data: {
'user': 'oi'
},
dataType: 'JSON',
success: function(data){
console.log(data);
}
});
return false;
});
Network:
Status Code: 419 unknown status
Request Headers > X-CSRF-TOKEN: oAiZm9n8xByExejoRVT3Yv2WKxkmoN1uZHkzHuAR
That is, ajax actually sends the token, but I'm not successful in the POST operation.