如果我将 remote: true 设置为我的表单authenticity_token 就会消失。我必须在我的表单中添加authentity_token: true 吗?缓存呢?如果我缓存表单,我必须添加authenticity_token:true?是authentity_token被缓存的问题吗?谢谢
问问题
39 次
1 回答
0
你jquery-rails
在你的应用程序中使用 gem 吗?这会自动将 CSRF 令牌添加到remote: true
AJAX 表单提交中:
https://github.com/rails/jquery-rails/blob/master/vendor/assets/javascripts/jquery_ujs.js#L69
// Make sure that every Ajax request sends the CSRF token
CSRFProtection: function(xhr) {
var token = rails.csrfToken();
if (token) xhr.setRequestHeader('X-CSRF-Token', token);
}
于 2019-10-31T18:39:23.950 回答