0

On laravel.log I get this:

[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

On browser console I get this:

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

My code is:

$(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);
        }
    });
});

On the head I have:

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

I've tried to comment csrf on Kernel.php and when I did it it worked... I have also added route group to the route:

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

});

Ricardo Barbosa
  • 157
  • 2
  • 14

0 Answers0