Introduction: In jquery Ajax POST request, the request, which Chinese in the background, display as garbled, how to solve it?
Introduction of the problem:
Copy Code code as follows:
var Regid = $ (' #oregion '). ComboBox (' GetValue ');
var sname = $ (' #sname '). Val ();
var sname = encodeURI ($ (' #sname '). Val (), "UTF-8");
if (regid!= "" &®id!= ' undefined ') {
$.ajax ({
Async:true,
Type: "POST",
DataType: "JSON",
URL: "<%=request.getcontextpath ()%>/secretary/ishasuser.do?regid=" +regid+ "&sname=" +sname,
Success:function (data) {
if (data.mes!= "" &&data.mes!=null) {
$.messager.alert (' Warning ', data.mes);
return false;
}
}
});
}
}
The above code in the Ff/chrome, the normal transmission of Chinese, but in IE, there are problems, in the background output information for garbled.
Questions to try:
1. Set the ContentType: "Text/plain; Charset=utf-8 ", the problem still exists
2. Re-check the JSP page where the Ajax code resides, all for the use of utf-8, but the problem persists
3. In the background Java code, the forced use of Utf-8, GBK, gb2312 encoding conversion, the problem persists
After analysis, it may be related to the content transmission in the browser or jquery, and can not be accurately determined at present.
Solutions:
Anterior segment: encodeURI ($ (DOM). Val (), "UTF-8"); Using encodeURI for encoding
Back-end Java code:
Urldecoder.decode (Inputstr, "UTF-8"): The back-end code decodes the string passed over the previous paragraph.
Summarize:
Finally, it is possible to display the Chinese language correctly with the string information passed over to the Ajax POST request.