Last active
December 22, 2016 07:05
-
-
Save jecyhw/643b5eff81df523c0fbe3a69dad36c3f to your computer and use it in GitHub Desktop.
spring boot ajax request with csrf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// <meta name="_csrf" th:content="${_csrf.token}"/> | |
// <meta 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); | |
}); | |
}); | |
//<input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}"/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment