HDTuto.com

Laravel 5.5 - POST <target url> 419 (unknown status) - can't ajax post data


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.




November 1, 2017 | Category : PHP Laravel JQuery Ajax Laravel 5 Laravel 5.5
Related Posts