This is because XMLHttp decodes the responseBody according to UTF-8 encoding when processing the returned responseText. If the data stream sent by the server is indeed UTF-8 encoded, then the Chinese characters will be displayed correctly, but if it is GBK or other Encoding will cause the above situation.
The solution is to add a header to the data stream returned by the server to indicate the encoding of the sent data stream, so that XMLHttp will not mess up.
Copy code The code is as follows:
header('Content-Type: text/html; charset=GB2312' );
http://www.bkjia.com/PHPjc/319777.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319777.htmlTechArticle This is because XMLHttp decodes the responseBody according to UTF-8 encoding when processing the returned responseText. If the server side The data stream sent is indeed UTF-8 encoded, so the Chinese characters will be correct...
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn