AleeRojas
12/11/2015 - 9:56 PM

Pasar los token en cabezeras

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);
};