jquery url中传递中文乱码怎么办


本文摘自PHP中文网,作者coldplay.xixi,侵删。

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

1

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代码:

如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

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代码:

码代码如下:

1

2

3

4

5

6

7

8

9

10

11

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中传递中文乱码怎么办的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

jQuery怎么判断是否为数字

jQuery判断是否为ie浏览器的方法

jQuery怎么去除css样式?

jQuery mobile是什么

浅谈vue中引入jQuery的方法

jQuery load方法加载文档时的中文乱码怎么办

详解jQuery中extend()和jQuery.fn.extend()的区别

如何使用jQuery对属性进行获取、设置和删除

jQuery怎么判断变量是否是数字

jQuery 2.x和1.x的区别是什么

更多相关阅读请进入《jQuery》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...