In Cakephp3 when the Csrf component is enabled. How I can use it in ajax call.
In this beforeSend
parameter of ajax csrf token is set in header. What is the val
Every form has a hidden _csrfToken
field that's automatically added when you have enabled the Csrf component. Now you can easily get the token of this field by jquery like $('[name="_csrfToken"]').val()
.
A ajax call will look like this:
$.ajax({
url: 'someUrl',
headers : {
'X-CSRF-Token': $('[name="_csrfToken"]').val()
},
type: 'post',
...
});