jQuery AJAX 请求 (Rails 3) 被重定向并返回空消息正文(仅使用 SSL)!

发布于 2024-09-05 16:10:15 字数 1031 浏览 8 评论 0原文

我正在尝试通过以下方式执行手动 jQuery AJAX 请求:

$("#user_plan_id").change(function() {
    $("#plan_container").load('/plans/' + this.value);
});

我的标头中包含“rails.js”文件和“<%= csrf_meta_tag %>”。

我从日志中看到请求正在发送到服务器(尽管没有真实性令牌...rails.js 是否这样做?),但响应是 302(找到)而不是 200,并且实际上没有获取任何数据呈现。

有什么想法吗?

编辑:我现在看到第一个请求重定向,并且正确的部分在重定向上呈现。但是,第二个响应的正文(在客户端)仍然为空。我猜测 jQuery 使用第一个响应,并且没有为重定向设置侦听器。我该如何解决这个问题?

另外,另一个注意事项:执行请求的页面是 HTTPS 页面。

我的日志内容如下:

Started GET "/plans/221168073" for 127.0.0.1 at Tue Jun 15 01:24:06 -0400 2010
  Processing by PlansController#show as HTML
  Parameters: {"id"=>"221168073"}
DEPRECATION WARNING: Using #request_uri is deprecated. Use fullpath instead. (called from ensure_proper_protocol at /Users/ernestsurudo/Sites/vidfolia/vendor/plugins/ssl_requirement/lib/ssl_requirement.rb:57)
Redirected to http://vidfolia.com/plans/221168073
Completed 302 Found in 1ms

事实证明,如果我关闭该页面的 SSL 要求,它就会起作用!但我仍然不知道为什么。所以我想我的问题是:解决方法是什么?

I'm trying to do a manual jQuery AJAX request the following way:

$("#user_plan_id").change(function() {
    $("#plan_container").load('/plans/' + this.value);
});

I have the "rails.js" file included in my header, and a "<%= csrf_meta_tag %>".

I see from my log that the request IS getting to the server (although without the authenticity token... does rails.js even do this?), but the response is a 302 (Found) rather than 200, and no data actually gets rendered.

Any ideas?

Edit: I now see that the first request redirects, and the proper partial gets rendered on the redirect. However, the 2nd response's body (on the client-side) is still empty. I'm guessing jQuery uses the first response and doesn't have a listener set up for the redirect. How do I get around this?

Also, another note: the page doing the requesting is an HTTPS page.

Here is what my log says:

Started GET "/plans/221168073" for 127.0.0.1 at Tue Jun 15 01:24:06 -0400 2010
  Processing by PlansController#show as HTML
  Parameters: {"id"=>"221168073"}
DEPRECATION WARNING: Using #request_uri is deprecated. Use fullpath instead. (called from ensure_proper_protocol at /Users/ernestsurudo/Sites/vidfolia/vendor/plugins/ssl_requirement/lib/ssl_requirement.rb:57)
Redirected to http://vidfolia.com/plans/221168073
Completed 302 Found in 1ms

It turns out that if I turn off SSL requirement for that page, it works! I still have no idea why, though. So I suppose my question is: what is the workaround?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情愿 2024-09-12 16:10:15

您是否有机会在某处设置 :protocol 为“http”?

do you by any chance set a :protocol to "http" somewhere?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文