[Vuejs]-POST Error in Ajax with Laravel, Vue-2, vue-composer

0đź‘Ť

As per your “XHR Error”, it means that when you’re making a post request you’re not sending CSRF Token.

As per laravel routing rules, middleware comes in action, and among different middleware there is ValidateCSRFToken. Which is checking if you’re sending valid CSRF token.

Kindly add that to your AJAX request.

See, if that works.

0đź‘Ť

You need to send the CSRF token.

Add this in the HEAD element:

<meta name="csrf-token" content="{{ csrf_token() }}">

If you use jQuery:

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

Leave a comment