I tried many things start from disable CSRF attack, it work, but I didn't think this is become a good solution.
Then I search on internet and I found that I have to put the token on header and send it with the ajax.
Steps:
Put this code on <head></head>
<meta th:if="${#httpServletRequest.remoteUser != null}" name="_csrf" th:content="${_csrf.token}" />Put this javascript code
<!-- default header name is X-CSRF-TOKEN -->
<meta th:if="${#httpServletRequest.remoteUser != null}" name="_csrf_header" th:content="${_csrf.headerName}" />
$(function() {
var token = $("meta[name='_csrf']").attr("content");
var header = $("meta[name='_csrf_header']").attr("content");
$(document).ajaxSend(function(e, xhr, options) {
xhr.setRequestHeader(header, token);
});
});
And then your ajax is ready to use