Set CSRF token

Can we set CSRF token automatically using rails-ujs npm?

Signed-off-by: Kenji Okimoto <okimoto@clear-code.com>
This commit is contained in:
Kenji Okimoto 2018-05-17 19:24:24 +09:00
parent c632380e1d
commit 7e1ec95198
No known key found for this signature in database
GPG Key ID: F9E3E329A5C5E4A1

View File

@ -146,11 +146,17 @@ window.addEventListener('load', () => {
if(this.previewAjax) {
this.previewAjax.abort();
}
const token = document.getElementsByName("csrf-token")[0].getAttribute('content')
var self = this;
new Promise(function(resolve, reject) {
self.previewAjax = $.ajax({
method: "POST",
url: "/api/regexp_preview",
headers: {
'X-CSRF-Token': token
},
data: {
regexp: self.params.setting.regexp,
time_format: self.params.setting.time_format,