Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save arteria/3304835 to your computer and use it in GitHub Desktop.
Save arteria/3304835 to your computer and use it in GitHub Desktop.
This is what I did to insert the CSRF token in backbone requests. This works with django.
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