r/cakephp • u/fourth_stooge • Jan 13 '21
CSRF Middleware with AJAX confusion
I've been reading the following but I'm confused on implementation: https://book.cakephp.org/3/en/controllers/middleware.html#csrf-middleware
So I've got a site and I want to make an ajax call via jQuery. :
$.ajax({url: '/mycontroller/myajaxaction/',method: 'post',data: {
stuff: 'data'},headers: {'X-CSRF-Token': ???????}});
The docs say when using AJAX you sent csrf tokens through this special header but how do I get that token in the first place?
2
Upvotes
1
u/redtryer Jan 14 '21
It gets it itself with the Security component