Tagged: csrf

405 error in laravel 5.6 using ajax

Problem: get error 405 when post URL

Laravel use csrf by default, you can add CSRF token in the form:

<form method="POST" action="/post_route" >
@csrf
...
</form>

But if you are using ajax to past data, you can add below code:

<!-- HTML-->
<meta name="csrf-token" content="{{ csrf_token() }}">
/* JQuery */
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});