Created
May 25, 2012 04:43
-
-
Save jacobh/2785812 to your computer and use it in GitHub Desktop.
Django ajax csrf coffeescript
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
$.ajaxSetup( | |
{ | |
beforeSend: (xhr, settings) -> | |
getCookie = (name) -> | |
cookieValue = null | |
if (document.cookie and document.cookie) isnt '' | |
cookies = document.cookie.split(';') | |
for cookie in cookies | |
console.log cookie | |
if cookie.substring(0, name.length+1) is name+'=' | |
cookieValue = decodeURIComponent( | |
cookie.substring(name.length+1) | |
) | |
break | |
return cookieValue | |
if not (/^http:.*/.test(settings.url) or /^https:.*/.test(settings.url)) | |
xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')) | |
} | |
) |
Ah cool. Thanks for the info.
…On May 25, 2012 2:04 PM, "Michael Ficarra" < ***@***.***> wrote:
## http://js2coffee.org
Reply to this email directly or view it on GitHub:
https://gist.github.com/2785812
No problem.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://js2coffee.org