ajaxgbk,php ajax 中文乱码问题解决办法(接收发送)utf-8 GBK GB2312


   
PHP发送中文、Ajax接收
只需在php顶部加入一句:
header('Content-type: text/html;charset=GB2312');
xmlHttp会正确解析其中的中文。
Ajax发送中文、PHP接收
这个比较复杂:
Ajax中先用encodeURIComponent对要提交的中文进行编码
PHP中:
$GB2312string=iconv( 'UTF-8', 'gb2312//IGNORE' , $RequestAjaxString);
PHP写入MySQL数据库
建立conn时,query一下set names "gb2312"
==================================================
注意红色部分!!!否则无法使用!!!具体原因自己猜!
iconv( "UTF-8","GBK" , $gametypes["name"]);
 
Tags:  ajax乱码 ajaxgbk

延伸阅读

最新评论

发表评论