


Solution to the problem of Chinese garbled characters being passed in the URL of jquery.ajax_jquery
May 16, 2016 pm 05:01 PMJQuery
JQuery default contentType: application/x-www-form-urlencoded
This is the reason why JQuery is garbled. When the character set is not specified, ISO-8859-1 is used
ISO8859-1, usually called Latin-1. Latin-1 includes additional characters indispensable for writing all Western European languages.
JQuery’s Ajax did not consider the issue of internationalization at all and used the European character set, which caused the problem of garbled characters when transmitting Chinese.
Our UTF-8 can solve this problem.
Ultimately, it means that you need to modify the JQuery code and explicitly declare that the contentType uses the utf-8 character set, which can solve the problem of GB2312 Chinese transmission.
1. Modify JQuery code
You only need to simply modify the JQuery code and add charset=UTF-8. In this way, there is no need to change web.config or change the encoding on the page, and there is no need to use escapc. (str) is then decoded 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:
function confirmcommit(){
var wlCompany = $("#wlCompany").val();//This contains Chinese
var wlId = $("#wlId").val();
var proposer = $("#proposer").val();
if(confirm("Are you sure you want to exchange the product?")){
$.ajax({
type:'POST',
url:'${pageContext.request.contextPath}/returnGoods/confrimExchangeGoods.do',
data:'wlCompany=' wlCompany '&wlId=' wlId '&proposer=' proposer, //pass the value directly
dataType:'text',
error:function(){
alert("JQuery AJAX Error!");
},
success:function(msg){
alert(msg);
return;
if(msg=='Exchange successful'){
document.location="${pageContext.request.contextPath}/orderItem/queryProduceItem.do?orderBusType=" ${orderBusType};
}
}
});
}
}
3. Java code:
public ActionForward confrimExchangeGoods(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
log.info("Confirm exchange confrimExchangeGoods start.............");
response.setCharacterEncoding("UTF-8"); //You need to set it here
String wlCompany = request.getParameter("wlCompany");
String wlId = request.getParameter("wlId");
String proposer = request.getParameter("proposer");
.....
}

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to solve the problem of garbled characters when importing Chinese data into Oracle?

How to solve the problem of garbled characters displayed on Win11 when booting? Two solutions to the garbled characters displayed on Win11 boot

How to get variables from PHP method using Ajax?

How to deal with garbled characters in Linux terminal

Strategies and techniques for solving Chinese garbled characters in Oracle database

jQuery Tips: Quickly modify the text of all a tags on the page

PHP vs. Ajax: Solutions for creating dynamically loaded content

Detailed explanation of the reasons and solutions for Chinese garbled characters displayed on PHP web pages
