Ajax通信でActionController::InvalidAuthenticityTokenしたときの対応
原因とか理由とかすっ飛ばして結論
送信するdataにauthenticity_token: $('meta[name="csrf-token"]').attr('content')}
を追加。
let ajax = function (method, data) {
data = $.extend(data, {authenticity_token: $('meta[name="csrf-token"]').attr('content')});
$.ajax({
type: method,
url: "hope/the/colona/is/orver",
timeout: 3000,
data: data,
dataType: 'json'
}).done(function (response, textStatus, jqXHR) {
console.log(response);
}).fail(function (jqXHR, textStatus, errorThrown) {
console.log(response);
});
};
Author And Source
この問題について(Ajax通信でActionController::InvalidAuthenticityTokenしたときの対応), 我々は、より多くの情報をここで見つけました https://qiita.com/r_ishimori/items/4f8db624e39d9e5ba459著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .