When i was working on my new laravel 5.5 application and i was making insert update delete using ajax and when i run post ajax request then i got ajax post request 419 unknown status error, you can also see bellow as it was.
POST http://localhost:8000/addmore 419 (unknown status)
send @ jquery.min.js:4
ajax @ jquery.min.js:4
(anonymous) @ addmore:55
dispatch @ jquery.min.js:3
r.handle @ jquery.min.js:3
I was checking and thinking a lot to find which is this error. But actually i didn't get well how to solve this error because nothing is return as error and didn't well understand to solve this. However, i found solution of this error, i understand what is issue, we require to send csrf token with ajax POST, DELETE and PUT method. So you have to add follwoing tag line in head tag:
<meta name="csrf-token" content="{{ csrf_token() }}">
Now you have to pass csrf token to ajax post request js code:
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
ok, now you can run your ajax jquery post request and it sould be works.
I hope you found your best solution.
Do you like below Tutorials ?
- How to Display Data in Angular 10?
- Angular 10 Routing Module Example Tutorial
- Angular 10 CRUD Operations with Web API Example
- Laravel 8 CRUD Operation Step By Step Tutorial
- Solved - Target class [ProductController] does not exist in Laravel 8
- Step by Step Form Validation in Laravel 8 Example
- Laravel 8 Image Upload with Preview Example
- Laravel 8 Multiple Images Upload with Preview Example