gpt4 book ai didi

jquery - 进行 ajax 调用时出现 406 Not Acceptable 错误

转载 作者:行者123 更新时间:2023-12-01 03:40:37 25 4
gpt4 key购买 nike

我的 .js.coffee 文件之一中有以下代码片段:

$.ajax({
url: '/attachinary_files/' + id
method: 'put'
}).done(//do something)

在我的浏览器控制台中,我收到错误:

406 Not Acceptable

我找不到原因。我在 application.js 文件中需要必要的文件,例如:

//= require jquery
//= require jquery_ujs
//= require_tree .

我找不到我丢失的东西。任何帮助将非常感激。谢谢:)

编辑:

Controller

def update
super
attachinary_file = AttachinaryFile.find(params[:id])
AttachinaryFile.where(attachinariable_id: attachinary_file.attachinariable_id)
.update_all(is_primary: false)
attachinary_file.update_column(:is_primary, true)
respond_to do |format|
flash.now[:notice] = nil
end
end

最佳答案

您缺少内容类型,这就是 HTTP 406 的原因错误。

更新您的 ajax 代码以包含响应的数据类型:

$.ajax({
url: '/attachinary_files/' + id
method: 'put'
dataType: 'script'
}).done(//do something)

请引用Data-Type (with jQuery)了解更多详情。

关于jquery - 进行 ajax 调用时出现 406 Not Acceptable 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21426943/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com