mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Make rails.js include the CSRF token in the X-CSRF-Token header with every ajax request.
This commit is contained in:
parent
ae19e4141f
commit
11061f410e
1 changed files with 16 additions and 0 deletions
|
@ -189,4 +189,20 @@
|
|||
document.on('ajax:complete', 'form', function(event, form) {
|
||||
if (form == event.findElement()) enableFormElements(form);
|
||||
});
|
||||
|
||||
Ajax.Responders.register({
|
||||
onCreate: function(request) {
|
||||
var csrf_meta_tag = $$('meta[name=csrf-token]')[0];
|
||||
|
||||
if (csrf_meta_tag) {
|
||||
var header = 'X-CSRF-Token',
|
||||
token = csrf_meta_tag.readAttribute('content');
|
||||
|
||||
if (!request.options.requestHeaders) {
|
||||
request.options.requestHeaders = {};
|
||||
}
|
||||
request.options.requestHeaders[header] = token;
|
||||
}
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
|
Loading…
Reference in a new issue