jquery ajax getJson 中文乱码

$(document).ready( function (){
                var waterUserName = $("textarea[name='waterUserName']");
                waterUserName.blur($.each(function (){
                	//alert(waterUserName.val());
                    $.getJSON("/../planWaterUser.do?actionMethod=getInfo&waterUserName="+encodeURI(encodeURI(waterUserName.val())),
                            function (data){
                                $("#trade").val(data.trade.name);
                                $("#valley").val(data.valley.name);
                                $("#district").val(data.district.name);
                            });
               }));
            });
关键代码: encodeURI(encodeURI(waterUserName.val()));
请注意是两次encodeURI
response.setHeader("Cache-Control", "no-cache");
		response.setContentType("text/json;charset=UTF-8");
		request.setCharacterEncoding("UTF-8");

		PrintWriter out = response.getWriter();

		String waterUserName = URLDecoder.decode(request.getParameter("waterUserName"),"utf-8");
关键代码:URLDecoder.decode(request.getParameter("waterUserName"),"utf-8");

解决ajax 与 java servlet中文乱码问题

参考文章:http://hi.baidu.com/sihillver/blog/item/4d6f32f592920325bc3109d7.html

相关推荐