ajax传值到后台,如果是中文字符串的话,可能会出现乱码的问题

$.ajax({
     type:'get',

url:
'updateAttendanceContent.action',
data:
'attenRegistContent.registId='+id+'&attenRegistContent.RContent='+encodeURI(value,"UTF-8"),
success:function(msg){ alert(msg); window.location.reload(); }, error:function(msg){ alert(
"更新失败!"+msg); } })

在前台ajax函数那 把要传的中文字符串使用encodeURI(str,enc)函数处理一下

如果后台还是有乱码的话,

在后台使用URLDecoder.decode(str,enc)处理一下字符串

    String RContent = null;

try { RContent = URLDecoder.decode(content.getRContent(),"UTF-8");

   } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } attenRegistContent.setRContent(RContent);

 

posted @ 2015-01-20 09:13  飞腾现舟、博  阅读(311)  评论(0编辑  收藏  举报