Created
December 11, 2015 21:56
-
-
Save AleeRojas/4d79935b5bf09c343876 to your computer and use it in GitHub Desktop.
Pasar los token en cabezeras
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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