Home > php教程 > php手册 > body text

PHP Ajax中文乱码问题解决方法

WBOY
Release: 2016-06-13 12:25:29
Original
1287 people have browsed it

是因为XMLHttp在处理返回的responstText的时候把responstBody按UTF-8编码进行解码的,如果服务器端送出的数据流的确是UTF-8编码,那么中文字就会正确显示,但如果是GBK或是其他编码则会出现上述情况。

解决的办法是在服务器端返回的数据流中加上一个header,指明送出的数据流是什么编码,这样XMLHttp就不搞乱了。

复制代码 代码如下:


header('Content-Type:text/html; charset=GB2312');

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template