Created
August 13, 2012 09:31
-
-
Save mbrochh/3338679 to your computer and use it in GitHub Desktop.
Get CSRF Token from cookie for AJAX calls against Django views
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
| function getCSRFToken() { | |
| var cookieValue = null; | |
| if (document.cookie && document.cookie != '') { | |
| var cookies = document.cookie.split(';'); | |
| for (var i = 0; i < cookies.length; i++) { | |
| var cookie = jQuery.trim(cookies[i]); | |
| if (cookie.substring(0, 10) == ('csrftoken' + '=')) { | |
| cookieValue = decodeURIComponent(cookie.substring(10)); | |
| break; | |
| } | |
| } | |
| } | |
| return cookieValue; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment