gpt4 book ai didi

ruby-on-rails - 为 AJAX 请求设计验证用户

转载 作者:数据小太阳 更新时间:2023-10-29 07:54:07 25 4
gpt4 key购买 nike

在需要用户(通过设计)的 AJAX 调用中处理重定向的最佳方式是什么?我想做类似的事情:

$('#love').click(function() {
$.get('/item/#{item.id}', function(data) {
if (data.redirect) { window.location.replace(data.redirect); return; }
});
});

但是,我不确定如何在过滤器(验证用户)处理“js”请求格式之前进行设计。有什么想法吗?

最佳答案

Devise 有专门的选项:http_authenticatable_on_xhr你可能会发现 this devise issue相关。

此外,我真的建议不要对 XHR 请求使用重定向。一旦你尝试在 Firefox 中使用它,你会发现自己陷入了痛苦的世界。在 Gecko 7.0 之前,当遵循 XHR 重定向时,firefox 不会保存原始请求的 header 。

根据 developer.mozilla.org XMLHttpRequest page:

From Gecko 7.0 headers set by setRequestHeader() are sent with the request when following a redirect. Previously these headers would not be sent.

关于ruby-on-rails - 为 AJAX 请求设计验证用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7004285/

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