Support the ongoing development of Laravel.io →
posted 9 years ago
Requests
Last updated 2 years ago.
0

console log the token, I cant see how you've defined the data to the element...

If you've only got one form element on the page try

var token = $('[name="_token"]').val();
Last updated 9 years ago.
0

Yeah sorry i forgot to mention.

I'm using

data-token="{{ csrf_token() }}

from the input field, and doing

alert(token);

returns the key. Thats why i find it so strange.

Last updated 9 years ago.
0
Solution

I added the token to my header like it suggests in the documentation.

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

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

Thank you that solved it!

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Detrol detrol Joined 1 Mar 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.