开发者

rjs is not working with IE

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 开发者_StackOverflow社区the ajax orders with files but... why?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜