Ajax post in jquery to submit garbled solution (GO)

Source: Internet
Author: User

Introduction: In jquery Ajax POST request, the request, the Chinese in the background, the display as garbled, how to solve it?

Introduction of the problem:

var Regid = $ (' #oregion '). ComboBox (' GetValue ');

var sname = $ (' #sname '). Val ();

var sname = encodeURI ($ (' #sname '). Val (), "UTF-8");

if (regid!= "" &&regid!= ' 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 Ff/chrome, can be normal delivery of Chinese, but under IE, there is a problem, in the background output information is garbled.

Problem attempts:

1. Set the ContentType: "Text/plain; Charset=utf-8 ", the problem still exists

2. Recheck the JSP page where the AJAX code is located, all using Utf-8, but the problem persists

3. In Java code in the background, forcing the use of Utf-8, GBK, gb2312 encoding conversion, the problem remains analyzed, it may be related to the browser or jquery content transmission, and currently can not be accurately determined.

Workaround : Previous paragraph: encodeURI ($ (DOM). Val (), "UTF-8"); Encode using encodeURI

Back-end Java code:

Urldecoder.decode (Inputstr, "UTF-8"): The back-end code decodes the string passed over the previous paragraph.

Summary: Finally, you can send the string information to the Ajax POST request, the normal display of Chinese.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.