Skip to content

Instantly share code, notes, and snippets.

@gcollazo
Created September 25, 2011 14:56
Show Gist options
  • Star 34 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save gcollazo/1240683 to your computer and use it in GitHub Desktop.
Save gcollazo/1240683 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);
};
@Mihai925
Copy link

Thanks! Finally something that works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment