Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Hardie's avatar

TokenMismatchException

Hi, i am using laravel 5 but in ajax call i have got one error like,

TokenMismatchException in VerifyCsrfToken.php line 46:

and also i have no exactly idea of token so can you help me please. i search over here and may be token is used in form but i want just listing records so is it compulsory of token ?

0 likes
4 replies
crazymonster's avatar

Tokens are used to protect your form for cross-side attacks. So, every time, L5 generates for you unique token with expiration.

Try it out: ">

When you use Ajax, just follow the code: $(function () { $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content') } }); });

1 like
yajra's avatar

Just follow Laravel's Documentation for CSRF at http://laravel.com/docs/5.0/routing#csrf-protection. Since your using ajax you need to setup the codes below:

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

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

Please or to participate in this conversation.