Home > Article > Web Front-end > What to do if Chinese garbled characters are passed in jquery url
The solution to Chinese garbled characters transmitted in jquery url: modify the JQuery code and add [charset=UTF-8], the code is [response.setCharacterEncoding("UTF-8");].
Recommended: "jquery video tutorial"
The operating environment of this tutorial: windows7 system, jquery1.4.4 version, This method works for all brands of computers.
Solution to passing Chinese garbled characters in jquery url:
1. Modify the JQuery code
Just simply modify the JQuery code. Just add charset=UTF-8, so there is no need to change web.config or change the encoding on the page, and there is no need to use escapc(str) to decode on the server side. How it is conveyed in English is also conveyed in Chinese.
Modify the jquery file used: 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 code:
is as follows:
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 code:
The code code is as follows:
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"); ..... }
Related free learning recommendations: JavaScript (video)
The above is the detailed content of What to do if Chinese garbled characters are passed in jquery url. For more information, please follow other related articles on the PHP Chinese website!