A complete solution for Garbled text when Atlas submits Chinese characters.

Source: Internet
Author: User

One of the most common problems in Ajax is that the server's response containing Chinese characters is garbled after being encoded by XMLHTTP. This problem also exists in Atlas.
This is not a big problem, but sometimes it is very troublesome. Now I have two solutions. If you need them, please refer to them.

1). Modify the Web. config encoding
<Globalization requestencoding = "UTF-8" responseencoding = "UTF-8"/> if your encoding is gb2312, this change may cause garbled characters on other pages, then you have to unify the UTF-8 encoding on the entire site.

2). encode the submitted string (recommended)

Static   String Formatencode ( String Str)
{
Byte[] Buffer=System. Text. encoding. Default. getbytes (STR );
ReturnSystem. Text. encoding. utf8.getstring (buffer );
}

This method is used to format the input string and then submit it.
The advantage of this method is that there is no need to modify the page encoding, and there is a low probability of problems after modification;
The disadvantage is that the encoding is performed once each commit, which degrades the performance. However, it is expected that the data submission is much less than the display, so the performance impact is limited.

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.