Getting error 419 unknown status Laravel while submitting login, registration form data through Ajax post, API Axios requests, Postman, and any other way, it means that CSRF authentication token or session has become invalid.
status code: 419 unknown status in laravel using ajax, api request on postman, Here are 3 solutions for fixing 419 unknown status Laravel 11, 10, 9, 8, 7 versions:
Solution 1
In this first solution, open your blade view file and add csrf token protection
your blade view file head section:
<head> <meta name="csrf-token" content="{{ csrf_token() }}"> </head>
Next, open again your blade view file, and use the csrf token
with ajax code in laravel; as follows:
$.ajaxSetup({ headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') } }); $.ajax({ });
Solution 2
The next solution, is if you still found status code: 419 unknown status with your Ajax request in laravel. So, you can try the following solution.
In this solution, we will show you how to send csrf token with your form data in laravel.
So, open your blade view file and add the following line of code into your blade view file head section:
<head> <meta name="csrf-token" content="{{ csrf_token() }}"> </head>
Now, you can see the following how to send csrf token with your form data using ajax in laravel:
$.ajax({ type: "POST", url: '/your_url', data: { somefield: "Some field value", _token: '{{csrf_token()}}' }, success: function (data) { console.log(data); }, error: function (data, textStatus, errorThrown) { console.log(data); }, });
Solution 3
The following third solution is quite similar to solution no 2.
Now, Add the following HTML code to your blade view file inside the head section:
<meta name="csrf-token" content="{{ csrf_token() }}">
Then, you can add csrf token with laravel ajax request as follows:
_token: '{!! csrf_token() !!}',
Csrf token with Ajax in laravel:
$.ajax({ url: 'yourUrl', dataType : 'json', type: 'POST', data: { _token: '{!! csrf_token() !!}', }, contentType: false, processData: false, success:function(response) { console.log(response); } });