whats wrong/problem to my code? anything im missing?
回答1:
While this question exists for a while, but no accepted answer is given I'd like to point you towards the solution. Because you're sending with ajax, and presumably still use the CSRF middleware, you need to provide an additional header with your request.
Add a meta-tag to each page (or master layout):
And add to your javascript-file (or section within the page):
This allows you to explicitly bypass specific routes that you do not want verified without disabling csrf validation globally.
回答5:
You can add your URLs to VerifyCsrfToken.php middleware. The URLs will be excluded from CSRF verification.
protected $except =["your url","your url/abc"];
回答6:
By default Laravel comes with CSRF middleware.
You have 2 options:
Send token in you request
Disable CSRF middleware (not recomended): in app\Http\Kernel.php remove VerifyCsrfToken from $middleware array
回答7:
for me this error cause of different stuff. i have two ajax call in my page. first one for save comment and another one for save like. in my routes.php i had this:
and i got 500 internal server error for my save like ajax call. so i change second line http request type to PUT and error goes away. you can use PATCH too. maybe it helps.
回答8:
Using post jquery instead had helped me to solve this problem