Laravel 5: Ajax Post 500 (Internal Server Error)

前端 未结 5 820
终归单人心
终归单人心 2020-12-10 07:54

I\'m trying to submit data to the database via ajax. The submit article page works fine without ajax. I\'ve added console.log() just to see if anything is going

5条回答
  •  醉话见心
    2020-12-10 08:31

    That's what I got exception 'Illuminate\Session\TokenMismatchException' in C:\xampp\htdocs\laravel-5\vendor\laravel\framework\src\Illuminate\Foundation\Htt‌​p\Middleware\VerifyCsrfToken.php:53

    You're hitting Laravel's CSRF protection.

    http://laravel.com/docs/5.1/routing#csrf-protection

    You need to pass the hidden _token field's value. This can be done automatically on all jQuery-initiated AJAX requests by doing this in your application's JS:

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

    Or, you can manually fetch and pass the value of the _token hidden field in each of your AJAX calls.

提交回复
热议问题