【发布时间】:2023-03-23 02:23:01
【问题描述】:
我使用 Rails 5.1 + webpack 当我使用
将 jQuery 包含到我的项目中时 plugins: [
new webpack.ProvidePlugin({
'jQuery': 'jquery',
'$': 'jquery',
'global.jQuery': 'jquery'
})
]
并尝试使用 jQuery.ajax PUT、POST 或 DELETE 请求,例如
var that = this;
$.ajax({
url: navigator_item.url,
method: 'DELETE',
success: function(res) {
...
}
});
我收到ActionController::InvalidAuthenticityToken。
但是,当我在 app.js 文件中包含带有下一行的 jQuery 时
import $ from 'jquery'
window.jQuery = $;
window.$ = $; // lazy fix if you want to use jQuery in your inline scripts.
这个在 shared.js 中
module.exports = {
resolve: {
alias: {
'jquery': 'jquery/src/jquery'
}
}
jQuery.ajax 工作正常。
当您将 jQuery 包含为插件时,有没有办法使用 jQuery.ajax?
【问题讨论】:
标签: javascript jquery ajax webpack ruby-on-rails-5