Home > php教程 > php手册 > ajax+php中文乱码的解决

ajax+php中文乱码的解决

WBOY
Release: 2016-06-13 11:33:49
Original
949 people have browsed it

由于XMLHTTP采用的是Unicode编码上传数据,而一般页面采用的是gb2312,这就造成显示页面时产生乱码。而当在获取页面时的XMLHttp返回的是utf-8编码,这就造成了显示产生乱码。
解决方法之一就是在PHP文件中显示声明为GB2312

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

而对于发送到服务器的中文进行转码。
如下
$_POST["content"]=iconv("UTF-8","gb2312",$_POST["content"]);
因而这样可以解决乱码问题

方法二,是都采用UTF-8编码。这里就不多说了

附测试例程
客户端





ajax post test



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