Skip to content

Instantly share code, notes, and snippets.

@tiagofernandez
Forked from justinperkins/jquery-auth-token.js
Last active December 20, 2015 22:19
Put auth-token on all jQuery Ajax requests.
$(function() {
$.ajaxSetup({
headers: { 'X-CSRFToken': $('[name="csrfmiddlewaretoken"]').val() }
});
});
// 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