ajax请求服务器数据包含中文处理以及MVC中下载文件名在ie和firef
发布时间:2020-12-16 00:59:04 所属栏目:百科 来源:网络整理
导读:转自 http://www.cnblogs.com/chengxiaohui/articles/1985163.html 一.使用ajax与服务器交互 不管是post方式还是get方式都应该对中文进行编码 只有这样 服务器端(ie浏览器 firefox不用)才能正确解析汉字 否则就是乱码。 二.在asp.net MVC中 ie跟firefox对下
转自 http://www.cnblogs.com/chengxiaohui/articles/1985163.html 一.使用ajax与服务器交互 不管是post方式还是get方式都应该对中文进行编码 只有这样 服务器端(ie浏览器 firefox不用)才能正确解析汉字 否则就是乱码。 二.在asp.net MVC中 ie跟firefox对下载文件名的处理不同 / ie通过编码实现正确的文件名/ public FileContentResult DownLoad() { string temp = "我是中国人!"; return File(System.Text.Encoding.UTF8.GetBytes(temp),"text/plain",Url.Encode("中国.txt")); } /firefox不必编码否则出现编码后的文件名/ public FileContentResult DownLoad() { string temp = "我是中国人!"; return File(System.Text.Encoding.UTF8.GetBytes(temp),"中国.txt"); } 兼容firefox跟ie的做法 通过Request.Browser.Browser.ToUpper()=="IE" 来判断是ie还是firefox(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |