VerifyCsrfToken.php上的TokenMismatchException:53

问题描述

在laravel.log上,我得到了:

[2020-08-20 15:51:08] local.ERROR: exception 'Illuminate\Session\TokenMismatchException' in /home/ialinves/public_html/cms/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrftoken.PHP:53

在浏览器控制台上,我得到了:

POST https://ial.pt/ajaxform 500 (Internal Server Error)

我的代码是:

$(document).ready(function () {
    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('Meta[name="csrf-token"]').attr('content')
        }
    });
    
    var nom = 'teste';
    
    $.ajax({
        type: 'POST',url: 'ajaxform',data: /*JSON.stringify({name: nom})*/{},//dataType: "json",success: function (data) {
            console.log(data);
        }
    });
});

我的头上有

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

我尝试在Kernel.PHP评论csrf,当我这样做时它就起作用了... 我也将路线组添加到路线:

Route::group(['middleware' => 'web'],function () {
//Form routes
Route::post('ajaxform','formulariosController@contacts');

});

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)