[置顶]jquery向.ashx文件post中文乱码问题的解决
posted @ 2011-03-25 21:55 LeeXiaoLiang 阅读(287) 评论(0) 编辑
置顶随笔 #
posted @ 2011-03-25 21:55 LeeXiaoLiang 阅读(287) 评论(0) 编辑
2011年7月12日 #
posted @ 2011-07-12 00:43 LeeXiaoLiang 阅读(841) 评论(2) 编辑
2011年4月1日 #
View Code
posted @ 2011-04-01 20:30 LeeXiaoLiang 阅读(159) 评论(0) 编辑
2011年3月25日 #
1.我的环境:vs2005,未装SP1补丁,不能创建Web应用程序,只能创建网站;jquery版本1.5.1
2.web.config中的相关配置
3.jquery的Post数据的写法
jquery Code
其中StudentName是中文
4.在.ashx文件中接收参数的写法
注意:如果没有contentType:"application/x-www-form-urlencoded; charset=UTF-8",则context.Request.Params["StudentName"]是乱码。
经过在.ashx中跟踪context.Request.ContentEncoding,可知jquery所post过来的数据采用的是gb2312编码,可能context.Request在接收到数据时默认采用utf-8进行解码,但是jquery在Post数据的时候却不是用的utf-8才导致.ashx的context.Request.Params["StudentName"]显示为乱码。
感觉比较奇怪的现象:
现象1:在不添加contentType:"application/x-www-form-urlencoded; charset=UTF-8",的情况下,在.ashx文件中使用下面的语句却可以正确显示字符串:
View Code
现象2:将web.config中的相关配置改为
<globalization requestEncoding="utf-8" responseEncoding="utf-8"/>
之后,不管是否加上contentType:"application/x-www-form-urlencoded; charset=UTF-8",后台的.ashx文件接收到的参数仍然是乱码。修改web.config之后网站编译的很慢且运行的也很慢。
参考文章:
1)http://dev.firnow.com/course/1_web/javascript/jsjs/20090303/157078.html
2)http://xyztony1985.blog.163.com/blog/static/361178201081754921150/
posted @ 2011-03-25 21:55 LeeXiaoLiang 阅读(287) 评论(0) 编辑
2010年12月7日 #
代码
posted @ 2010-12-07 01:00 LeeXiaoLiang 阅读(62) 评论(0) 编辑
代码
posted @ 2010-12-07 00:45 LeeXiaoLiang 阅读(55) 评论(0) 编辑
2010年12月4日 #
代码很简单,这里就不累述了。看代码如下:
C#
posted @ 2010-12-04 20:17 LeeXiaoLiang 阅读(38) 评论(0) 编辑
posted @ 2010-12-04 01:15 LeeXiaoLiang 阅读(71) 评论(0) 编辑
2010年8月19日 #
posted @ 2010-08-19 17:02 LeeXiaoLiang 阅读(181) 评论(0) 编辑
posted @ 2010-08-19 10:37 LeeXiaoLiang 阅读(106) 评论(0) 编辑
2010年8月17日 #
posted @ 2010-08-17 15:29 LeeXiaoLiang 阅读(84) 评论(0) 编辑