Home > Web Front-end > JS Tutorial > What to do if Chinese garbled characters are passed in jquery url

What to do if Chinese garbled characters are passed in jquery url

coldplay.xixi
Release: 2020-11-30 15:24:23
Original
2512 people have browsed it

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");].

What to do if Chinese garbled characters are passed in jquery url

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}
Copy after login

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};
    }
}
});
     }
 }
Copy after login

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");
     .....
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template