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

Highco's avatar

CSRF-Token from {{csrf_token()}} on IE never match

When i make ajax call like this:


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

$.ajax({
            method : 'POST',
            url : '/article',
            data: {'content' : 'text'},
        }).done(function (data) {
            callback(data)
        }).fail(function () {
            alert('Error');
        });

When it check csrf token, it allways return false in file /vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php line 67 (from function tokensMatch() line107)

And this ONLY on internet explorer... I try to send it via data, get token from {{csrf-field}},etc... Nothing better.

An idea ?

0 likes
4 replies
jlrdw's avatar
 '_token': '{!! csrf_token() !!}

That's neat I did not know you could do that Direct.

Snapey's avatar

That's neat I did not know you could do that Direct.

Only if the javascript is embedded in your view file. If the js is in a separate file then it never gets exposed to blade.

djooo's avatar

I can't reproduce the error with IE. Have you installed extras dependencies that could "break" the proper functioning ? if so, comment these dependencies and reactive one by one.

The problem occur if you change your session's driver?

Please or to participate in this conversation.