轨道发送了错误的内容类型的Ajax响应 [英] rails sending the wrong content-type in ajax response

查看:148
本文介绍了轨道发送了错误的内容类型的Ajax响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在挣扎可怕的一天有以下问题更好的一部分:

I have been struggling terribly for the better part of the day with the following problem:

  • 在我有一个Rails 3.1的应用程序 - 运行正常
  • 我想一些Ajax添加到它

不过,无论我怎么努力,Rails的坚持在响应首部发送了错误的内容类型。

However, no matter what I try, Rails insists on sending the wrong content-type in the response header.

#the form    
= form_for @signup, :url => '/signup', :remote => true do |f|
    = f.text_field :email, :class => 'email', :size => 26
    = f.submit 'Notify me'

#In the controller
def create
  respond_to do |format|
    format.js { render :content_type => 'text/javascript', :layout => false}
  end
end

#the JS file: create.js.erb
alert('HI!');

这是行不通的,而我认为它应该。检查与萤火虫服务器响应它告诉我响应头具有一个内容类型的的text / html 。我想,这就是为什么它不工作(作为一个新生成的应用程序,使用同样的jQuery护栏宝石也可以用文/ JavaScript的头响应。

This is not working, while I think it should. Inspecting the server response with Firebug it tells me the response header has a content-type of text/html. I figure this is why it isn't working (as on a newly generated app, using the same jquery-rails gem it responds with a text/javascript header.

服务器的的它与JS响应:

The server says it's responding with JS:

Processing by SignupsController#create as JS

但由于某种原因拒绝发送正确的头。我失去了去哪里寻找下一个。

But is somehow refusing to send the correct header. I am lost on where to look next.

任何帮助或方向是在哪里寻找下一个会是极大的AP preciated! 欧文

Any help or direction as to where to look next would be greatly appreciated! Erwin

推荐答案

确定找到了解决办法,

因此​​,在应用程序控制器的after_filter被重写内容类型。他们在里面了处理。因此,它是覆盖我的声明。

So an after_filter in application controller was overriding the content-type. And they are processed inside out. So it was overwriting my declarations.

这篇关于轨道发送了错误的内容类型的Ajax响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆