关于Rails Ajax 乱码,request.xhr--- Ajax提交

关于Rails Ajax 乱码(转 http://www.railscn.com/viewthread.php?tid=2326&extra=page%3D2)
当我不用Ajax时,采用下面的方法显示正常
       class ApplicationController < ActionController::Base
       before_filter :set_charset
       def set_charset
           @headers["Content-Type"] = "text/html; charset=GB2312"
       end
       end
如果我采用Ajax ,中文时显示了,可是Ajax不起作用了
解决方法:
  before_filter :set_charset
  def set_charset   
    if request.xhr?   
      @headers['Content-Type'] = "text/javascript; charset=GB2312"   
    else      
      @headers['Content-Type'] = "text/html; charset=GB2312"   
    end
  end
注意红色的字体哦!!

你可能感兴趣的:(JavaScript,html,Ajax,PHP,Rails)