Forked from justinperkins/jquery-auth-token.js
Last active
December 20, 2015 22:19
Put auth-token on all jQuery Ajax requests.
This file contains 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
$(function() { | |
$.ajaxSetup({ | |
headers: { 'X-CSRFToken': $('[name="csrfmiddlewaretoken"]').val() } | |
}); | |
}); |
This file contains 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
// Not really recommended, since Backbone relies on jQuery for Ajax anyway | |
var sync = Backbone.sync; | |
Backbone.sync = function(method, model, options) { | |
options.beforeSend = function(xhr) { | |
xhr.setRequestHeader('X-CSRFToken', $('[name="csrfmiddlewaretoken"]').val()); | |
}; | |
return sync(method, model, options); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment