ajax post in laravel 5 return error 500 (Internal Server Error)

后端 未结 12 1056
不知归路
不知归路 2020-11-29 05:13

this is my test ajax in laravel 5 (refer below)

$(\"#try\").click(function(){
    var url = $(this).attr(\"data-link\");
    $.ajax({
        url: \"test\",
         


        
12条回答
  •  不知归路
    2020-11-29 06:05

    In App\Http\Middleware\VerifyCsrfToken.php you could try updating the file to something like:

    class VerifyCsrfToken extends BaseVerifier {
    
        private $openRoutes =
        [
            ...excluded routes
        ];
    
        public function handle($request, Closure $next)
        {
            foreach($this->openRoutes as $route)
            {
                if ($request->is($route))
                {
                    return $next($request);
                }
            }
    
            return parent::handle($request, $next);
        }
    };
    

    This allows you to explicitly bypass specific routes that you do not want verified without disabling csrf validation globally.

提交回复
热议问题