IE8 忽略 Rails 3.1 的 ajax 响应
我使用 Rails 3.1 和 AJAX 来创建一些模型。
视图如下所示:
<%= link_to 'Vote', votes_path, :method => :post, :remote => true %>
控制器:
...
def create
...
respond_to do |format|
format.js { render :layout => false }
end
end
...
最后,.js.erb 如下所示:
alert('Hi there!');
在 Chrome、FF 和 Safari 中,它按我的预期工作,创建模型并显示警报。在 IE8 中,它创建模型但不执行 javascript。 我认为这是 jquery-rails 或其他东西的一个奇怪的问题,因为在 Rails 3.0.9 中它工作得很好。
谢谢你!
PD 我也尝试过 format.js { render :layout =>; false, :content_type => "text/javascript" }
但仍然不起作用。
I'm using Rails 3.1 and AJAX for creating some models.
The view looks like:
<%= link_to 'Vote', votes_path, :method => :post, :remote => true %>
And the controller:
...
def create
...
respond_to do |format|
format.js { render :layout => false }
end
end
...
Finally, the .js.erb looks like:
alert('Hi there!');
In Chrome, FF and Safari it works as I expected, creating the model and displaying the alert. In IE8, it creates the model but it doesn't execute javascript.
I think its a weird problem with jquery-rails or something, because with Rails 3.0.9 it works well.
Thank you!
P.D. I also tried format.js { render :layout => false, :content_type => "text/javascript" }
but still doesn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在其他版本的资源管理器(新旧版本)中是否也会发生这种情况?
您是否调试过问题是在执行ajax调用时还是在接收时?您收到任何错误报告吗?
您是否在布局中包含 csrf_meta_tags ?他们在执行 POST 时真的会把事情搞砸。
我建议您使用 Internet Explorer 8 调试器:
Does it also happen in other versions of Explorer, newer of older?
Have you debugged if the problem is at the time of performing the ajax call or when receiving it? Do you get any error report?
Are you including the csrf_meta_tags in the layout? They can really mess up things when performing a POST.
I would advise you to use the Internet Explorer 8 debugger:
我刚刚找到了调试
jquery_ujs
远程调用的解决方案。问题在于字符集响应(我认为)。由于某种原因,我必须明确指定:
format.js { render :layout =>; false, :content_type => "text/javascript; charset=UTF-8" }
请不要使用 IE8 :D
I just found the solution debugging
jquery_ujs
remote calls. The problem was with charset response (I think).For some reason I must specify explicitly:
format.js { render :layout => false, :content_type => "text/javascript; charset=UTF-8" }
Please, don't use IE8 :D