Skip to content

Instantly share code, notes, and snippets.

@thelonecabbage
Created September 8, 2013 12:21
Show Gist options
  • Save thelonecabbage/6484336 to your computer and use it in GitHub Desktop.
Save thelonecabbage/6484336 to your computer and use it in GitHub Desktop.
Using CSRF in jQuery
function create_task(title) {
return $.ajax({
url: '/api/v1/task/',
dataType: "application/json",
data: JSON.stringify({
title: title
}),
type:'POST',
contentType:'application/json',
processData: false,
headers: {
'X-CSRFToken' :(document.cookie.match(/csrftoken=([0-9a-zA-Z]*)/) || ['']).pop()
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment