in laravel, so will be similar in cake.
Replace _token with the name of token in cake.
Don’t disable csrf.
Really if you are new to JS and ajax, you should study it first via some tutorials and maybe Youtube videos. The forums keep getting these questions, where all it takes is a couple of tutorials first.
Ok, thanks for the link to the tutorial on CSRF.
The strange thing is, even if I’m disabling CSRF, I still get the “CSRF token mismatch” error message.
I tried disabling it in the controller with:
function beforeFilter(Event $event) {
$this->getEventManager()->off($this->Csrf);
}
Also, I tried creating a cookie in AppController with:
But I’m not sure how to fetch it with javascript.
Also, tried creating a token in javascript:
var token = 'test';
xml_http.setRequestHeader('X-CSRF-Token', token);
Still no luck.
Update
By removing CsrfProtectionMiddleware from Application.php, the error disappears. Still need to figure out how to have it enabled and get the cookie-token-value by javascript I guess…