rappasoft
1792
16
General

Laravel 5 AJAX TokenMismatchException

Posted 4 years ago by rappasoft

I have a page that starts about 20 AJAX requests on load, and loads the contents in.

I have a meta tag in the header called _token, and I have this as my ajaxSetup:

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

It's hit or miss, sometimes when I run the script all 20 requests finish without problem, other times, 15 may finish and 5 will fail or 10 will finish and 10 will fail. Each time different ones finish and fail. The logs fill up with TokenMistatchExceptions.

So I tried sending a fresh csrf_token() with each request, and same problem, the page source even shows they're all the same.

Is anyone else having issues? Or is there something i'm missing with L5?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.