Spring boot + security 사용시 ajax 처리
spring boot + spring security 사용중인데,
일반적인 ajax call 하니 시큐리티에서 막아버리는것 같다.
head 태그 사이에 추가하자
<meta name="_csrf" th:content="${_csrf.token}"><meta name="_csrf_header" th:content="${_csrf.headerName}">
ajax 호출 전에 추가 (공통으로 셋팅해놓으면 편하다.)
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); });
Leave a comment