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
相关推荐
newthon 2019-12-07
chinewwen 2011-08-07
我只是个程序员 2014-06-30
Anything 2016-01-04
RanQi0 2014-05-28
82473264 2011-09-26
wujiajax 2017-10-02
yigeng 2017-10-02
sunnygirls 2017-10-02
Dolphinsz 2017-01-03
只争朝夕 2016-11-21
cfh00 2012-06-26
86281940 2016-08-13
青盲 2016-07-21
yigeng 2016-07-11
Dolphinsz 2016-04-09