Skip to content

Instantly share code, notes, and snippets.

@AleeRojas
Created December 11, 2015 21:56
Show Gist options
  • Save AleeRojas/4d79935b5bf09c343876 to your computer and use it in GitHub Desktop.
Save AleeRojas/4d79935b5bf09c343876 to your computer and use it in GitHub Desktop.
Pasar los token en cabezeras
var oldSync;
oldSync = Backbone.sync;
Backbone.sync = function(method, model, options) {
var csrfSafeMethod;
csrfSafeMethod = function(method) {
return /^(GET|HEAD|OPTIONS|TRACE)$/.test(method);
};
options.beforeSend = function(xhr, settings) {
if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
xhr.setRequestHeader('X-CSRFToken', $.cookie('csrftoken'));
}
};
return oldSync(method, model, options);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment