You may need to add the csrf token to the request.
Obtaining a token using JSTL should be fairly simple. If you are using Thymeleaf, here is how to get it.
<script th:inline="javascript"> /*<![CDATA[*/ var _csrf_token = /*[[${_csrf.token}]]*/ ''; var _csrf_param_name = /*[[${_csrf.parameterName}]]*/ ''; /*]]>*/ </script>
Then add it to your query:
var requestData = { 'paramA': paramA, 'paramB': paramB, }; requestData[_csrf_param_name] = _csrf_token;
If all goes well, the request should include something like _csrf: 1556bced-b323-4a23-ba1d-5d15428d29fa (csrf token) and you will get 200 instead of 403.
source share