impress/app/assets/javascripts/ajax_auth.js

21 lines
494 B
JavaScript
Raw Normal View History

2012-01-26 11:30:53 -08:00
(function () {
var CSRFProtection;
var token = $('meta[name="csrf-token"]').attr("content");
if (token) {
CSRFProtection = function (xhr, settings) {
var sendToken =
typeof settings.useCSRFProtection === "undefined" || // default to true
settings.useCSRFProtection;
if (sendToken) {
xhr.setRequestHeader("X-CSRF-Token", token);
}
};
} else {
CSRFProtection = $.noop;
}
2012-01-26 11:30:53 -08:00
$.ajaxSetup({
beforeSend: CSRFProtection,
});
2012-01-26 11:30:53 -08:00
})();