2007-09-28

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

关键字: request.xhr
关于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
注意红色的字体哦!!
评论
发表评论

提醒: 该博客已发表在公共论坛,博客所有留言会成为论坛回贴,留言请注意遵守论坛发贴规则

您还没有登录,请登录后发表评论

simon_lin
搜索本博客
最近加入圈子
存档
最新评论