Set CSRF token header for jQuery.
-
Yarn
yarn add jquery.csrf
-
NPM
npm install jquery.csrf
- Include jQuery and jquery.csrf.js:
<script src="https://code.jquery.com/jquery.js"></script>
<script src="jquery.csrf.js"></script>
- Include
meta
tag in your page with the CSRF-token:
<meta name="csrf-token" content="myCSRFtoken">
- Now, whenever you make AJAX request using jQuery,
X-CSRF-Token
will be set tomyCSRFtoken
.
// Example:
$("body").load("ajax/test.html");
Copyright © 2017 Jianqiu Xiao [email protected] under The MIT License.