I want to make a ajax call using $.POST. But I am getting 403 error. But GET works perfectly fine. My code is:
var url = \"/xyz/abc/subscribe?name=\"+name;
$
You might want to add the csrf token to the request.
Obtaining the token using JSTL should be pretty straightforward. If you are using Thymeleaf, here is how to obtain it.
Then, add it to your request:
var requestData = {
'paramA': paramA,
'paramB': paramB,
};
requestData[_csrf_param_name] = _csrf_token; // Adds the token
$.ajax({
type: 'POST',
url: '...your url...',
data: requestData,
...
});
If everything goes well, the request should include something like _csrf:1556bced-b323-4a23-ba1d-5d15428d29fa (the csrf token) and you will get a 200 instead of a 403.