rjs 不适用于 IE

发布于 2024-09-16 23:39:17 字数 499 浏览 4 评论 0原文

我的代码:

# app/controllers/log_controller.rb

class LogController < ApplicationController
  def in
    @user = User.login(params[:login])
    respond_to do |format|
      format.js
    end
  end
end

# app/views/log/in.js.erb
redirect_to("/myprofile")

# public/javascript/application.js
function redirect_to(url) { location.href = url; }

在 FF、Chrome 和 Safari 以及每个浏览器中都运行良好。用户登录系统并重定向到她的个人资料,但在资源管理器中它要求下载文件!您知道,那个黄色小条要求用户下载文件。我认为错误的是 ajax 命令与文件,但是......为什么?

My code:

# app/controllers/log_controller.rb

class LogController < ApplicationController
  def in
    @user = User.login(params[:login])
    respond_to do |format|
      format.js
    end
  end
end

# app/views/log/in.js.erb
redirect_to("/myprofile")

# public/javascript/application.js
function redirect_to(url) { location.href = url; }

In FF and Chrome and Safari and every browser works great. The user log in the system and redirects to her profile, but in explorer it ask for downloading files! You know, that little yellow bar asking the user to download a file. I think is mistaking the ajax orders with files but... why?

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

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

发布评论

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

评论(1

清秋悲枫 2024-09-23 23:39:17

听起来像是 MIME 类型的问题。这是描述问题和解决方案的帖子:http://agilerails.wordpress.com/2009/05/27/ie-throws-file-download-security-warning-on-form-submit/

基本上,问题出在 IE 的请求标头上。您必须使用 text/html 的 MIME 类型才能使其工作。有关它的更多信息,请参见

您有几个选择:

  • 通过用户代理检测 IE 并按照描述发送文本/html 此处
  • 在请求响应优先级列表中的 format.js 上方添加 format.html

编辑:不太确定这是否是您想要的请求,因为您也在执行 AJAX,但在最后一步,当您进行重定向时,您应该提供 text/html MIME 类型。

Sounds like an issue with MIME type. Here's a post describing the problem and a solution : http://agilerails.wordpress.com/2009/05/27/ie-throws-file-download-security-warning-on-form-submit/.

Basicaly, the problem is with IE's request headers. You'll have to use a MIME Type of text/html to make it work. More info about it in this SO question.

You have a few options :

  • Detect IE by user-agent and send text/html as described here
  • Add format.html above format.js in the request response priority list

Edit: no quite sure this is what you want for all requests, since you're also doing AJAX, but at that last step, when you make the redirection, you should be serving a text/html MIME Type.

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