rjs 不适用于 IE
我的代码:
# 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来像是 MIME 类型的问题。这是描述问题和解决方案的帖子:http://agilerails.wordpress.com/2009/05/27/ie-throws-file-download-security-warning-on-form-submit/。
基本上,问题出在 IE 的请求标头上。您必须使用 text/html 的 MIME 类型才能使其工作。有关它的更多信息,请参见
您有几个选择:
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 :
format.html
aboveformat.js
in the request response priority listEdit: 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.