: This article mainly introduces how to solve Ajax Chinese garbled characters in PHP. For more information about PHP tutorials, see. Recently, Ajax technology has been used in PHP projects to improve user experience. However, a new problem is introduced, that is, the Chinese characters in responstText returned by Ajax are mostly garbled, even if I specify the page encoding as a UTF-8.
This is because XMLHttp decodes responstBody according to UTF-8 encoding when processing returned responstText. if the data stream sent by the server is indeed UTF-8 encoding, the text will be correctly displayed, however, if it is GBK or other encoding, the above situation will occur.
The solution is to add a header to the data stream returned by the server to specify the encoding of the sent data stream, so that XMLHttp will not mess up.
Header ('content-Type: text/html; charset = <strong> GB2312 </strong> ');
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.
The above describes how to solve the problem of Ajax Chinese garbled characters in PHP, including the GB2312 content, and hope to help those who are interested in PHP tutorials.