Skip to content

Instantly share code, notes, and snippets.

@kostnikolas
Created September 8, 2015 12:34
Show Gist options
  • Save kostnikolas/4bd74078db8e4167d3ad to your computer and use it in GitHub Desktop.
Save kostnikolas/4bd74078db8e4167d3ad to your computer and use it in GitHub Desktop.
getCookie = (name) ->
for cookie in document.cookie.split ';' when cookie and name is (cookie.split '=')[0]
return decodeURIComponent cookie[(1 + name.length)...]
null
$.ajaxSetup
beforeSend: (xhr, settings) ->
unless (/^http:.*/.test settings.url) or (/^https:.*/.test settings.url)
xhr.setRequestHeader "X-CSRFToken", getCookie 'csrftoken'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment