Jquery
jquery default contenttype:application/x-www-form-urlencoded
This is the reason jquery is garbled, when the character set is not specified, is the use of iso-8859-1
Iso8859-1, usually called Latin-1. Latin-1 includes additional characters that are indispensable for writing all Western European languages.
jquery Ajax does not take into account the internationalization of the problem, the use of the European character set, so it caused the transfer of Chinese garbled problem.
And our UTF-8 can solve this problem.
Finally refers to the need to modify the jquery code, the explicit declaration contenttype use the Utf-8 character set, can solve the problem of GB2312 Chinese delivery.
1. Modify the jquery code
Simply modify the jquery code, plus the Charset=utf-8, so that you don't need to change what web.config or what is encoded in the page, and you don't need to use ESCAPC (str) to decode the server. How to transfer English, how to transfer Chinese.
To modify a used jquery file: 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:
Copy Code code as follows:
function Confirmcommit () {
var wlcompany = $ ("#wlCompany"). Val ()//This contains Chinese
var wlid = $ ("#wlId"). Val ();
var proposer = $ ("#proposer"). Val ();
if (Confirm ("Confirm to replace it")) {
$.ajax ({
Type: ' POST ',
URL: ' ${pagecontext.request.contextpath}/returngoods/confrimexchangegoods.do ',
Data: ' wlcompany= ' +wlcompany+ ' &wlid= ' +wlid+ ' &proposer= ' +proposer,//Direct transfer value
DataType: ' Text ',
Error:function () {
Alert ("JQuery AJAX error!");
},
Success:function (msg) {
Alert (msg);
Return
if (msg== ' replacement success ') {
document.location= "${pagecontext.request.contextpath}/orderitem/queryproduceitem.do?orderbustype=" +${ Orderbustype};
}
}
});
}
}
3. Java code:
Copy Code code as follows:
Public Actionforward confrimexchangegoods (actionmapping mapping,
Actionform form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
Log.info ("Confirmation of the replacement confrimexchangegoods start ..."), and the
Response.setcharacterencoding ("UTF-8"); Here to set the
String Wlcompany = Request.getparameter ("Wlcompany");
String wlid = Request.getparameter ("wlid");
String proposer = Request.getparameter ("proposer");
.....
}