PHP Ajax Chinese garbled problem solution_PHP tutorial

WBOY
Release: 2016-07-21 15:48:12
Original
784 people have browsed it

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' );

www.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...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template