【发布时间】:2020-09-16 18:10:59
【问题描述】:
我有
(家庭控制器)
def default
users = Users.all
respond_to do |format|
format.html
format.json { render json: users}
end
end
和
(查看)
axios({
method: 'get',
url: '/home',
headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }
}).then(response => console.log(response))
带有 json 标头,但我得到了
ActionController::UnknownFormat (LoginController#default is missing a template for this request format and variant.
request.formats: ["application/json"]
request.variant: []):
带有 http 错误 406(不可接受)
感谢您的帮助:)
编辑:
我发现了问题,实际上我的 Rails 将我的请求作为 '/homehome' 我不知道为什么?我在 axios url 参数中将 '/home' 更改为 '' 并且它现在可以工作了,但我仍然不明白发生了什么??
我的 Web 控制台中也有此消息
A cookie associated with a cross-site resource at http://youtube.com/ was set
without the `SameSite` attribute. A future release of Chrome will only deliver
cookies with cross-site requests if they are set with `SameSite=None` and
`Secure`. You can review cookies in developer tools under
Application>Storage>Cookies and see more details at
https://www.chromestatus.com/feature/5088147346030592 and
https://www.chromestatus.com/feature/5633521622188032.
【问题讨论】:
标签: javascript html ruby-on-rails ruby