Skip to content

Instantly share code, notes, and snippets.

@AndrewJHart
Forked from gcollazo/Backbone.sync_csrftoken.js
Created November 14, 2013 15:47
Show Gist options
  • Save AndrewJHart/7469074 to your computer and use it in GitHub Desktop.
Save AndrewJHart/7469074 to your computer and use it in GitHub Desktop.
Set backbone to automatically set the CSRF header token for django for all ajax requests
var oldSync = Backbone.sync;
Backbone.sync = function(method, model, options){
options.beforeSend = function(xhr){
xhr.setRequestHeader('X-CSRFToken', CSRF_TOKEN);
};
return oldSync(method, model, options);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment