jquery url中传递中文乱码的解决办法:将jquery的代码加以修改,加上【charset=utf-8】,代码为【response.setcharacterencoding(utf-8);】。
推荐:《jquery视频教程》
本教程操作环境:windows7系统、jquery1.4.4版本,该方法适用于所有品牌电脑。
jquery url中传递中文乱码的解决办法:
1、修改jquery代码
只需要简单的将jquery的代码加以修改,加上charset=utf-8就可以了,这样不需要改变改什么web.config或什么在页面中改编码什么的了,也不需要用escapc(str)再在服务端解码。英文怎么传递,中文也怎么传递。
修改用到的jquery文件:jquery-1.4.4.min.js
ajaxsettings:{url:location.href,global:true,type:"get",contenttype:"application/x-www-form-urlencoded;charset=utf-8",processdata:true,async:true,xhr:function(){return new e.xmlhttprequest}
2、js代码:
如下:
function confirmcommit(){ var wlcompany = $("#wlcompany").val();//这里含有中文 var wlid = $("#wlid").val(); var proposer = $("#proposer").val(); if(confirm("确认要换货吗")){$.ajax({type:'post',url:'${pagecontext.request.contextpath}/returngoods/confrimexchangegoods.do',data:'wlcompany='+wlcompany+'&wlid='+wlid+'&proposer='+proposer, //直接传值datatype:'text',error:function(){ alert("jquery ajax error!"); },success:function(msg){ alert(msg); return; if(msg=='换货成功'){ document.location="${pagecontext.request.contextpath}/orderitem/queryproduceitem.do?orderbustype="+${orderbustype}; }}}); } }
3、java代码:
码代码如下:
public actionforward confrimexchangegoods(actionmapping mapping, actionform form, httpservletrequest request,httpservletresponse response) throws exception {log.info("确认换货 confrimexchangegoods start...............");response.setcharacterencoding("utf-8"); //这里要设置一下string wlcompany = request.getparameter("wlcompany");string wlid = request.getparameter("wlid");string proposer = request.getparameter("proposer"); .....}
相关免费学习推荐:javascript(视频)
以上就是jquery url中传递中文乱码怎么办的详细内容。