How to solve garbled characters in Ajax get Chinese

Source: Internet
Author: User

Author: ominous

Add the character encoding method:
Response. setheader ("charset", "gb2312 ");

The original description is as follows:

When you use get in Ajax to read pages, most of the Chinese characters in responsetext will be garbled, because the resposebody uses UTF-8 encoding by default when XMLHTTP processes the returned responsetext, if the server sends a UTF-8 data stream, the Chinese characters are correctly displayed, and the Chinese characters on the page are garbled when the encoding of the read page is GBK or gb2312.

There are two solutions:

1. Add a header to the sent stream to specify the specific encoding stream to be sent:

PHP: Header ('content-type: text/html; charset = gb2312 ');
ASP: Response. charset ("gb2312 ")
JSP: Response. setheader ("charset", "gb2312 ");

2. Use UTF-8 encoding to save HTML documents

 

Related Article

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.