使用prototype的Ajax.Updater接口,使用接口evalScripts属性直接执行ajax结果,调用页面编码是gb2312,发现回吐的ajax内容中文乱码。是由于ajax默认使用utf-8编码,与页面的编码冲突导致乱码。
a.htm中的内容:
<java
<script language="javascript">
function doajax(){var ajax = new Ajax.Updater(’div_ajax’,"b.php",{onComplete:function(){},evalScripts:true});}
</script>
<div id="div_ajax ">&amp;nbsp;</div>
<input type="button" value="click" onclick="javascript:doajax();" />
被调用的b.php中内容:</p>
header('Content-type: text/html;charset=gb2312');
//smarty处理中文模板
echo 'Ajax.Updater测试中文乱码';
其中header(‘Content-type: text/html;charset=gb2312′);在开始就强行指定编码,解决问题。
转载本站文章请注明,转载自:神秘果
本文链接: http://www.shenmiguo.com/archives/2009/263_php-ajax-messy-code.html

十二月 25th, 2011 at 08:46
This infromtaion is off the hizool!
十二月 25th, 2011 at 17:06
5KFVYq nrucpwqmhapf
十二月 26th, 2011 at 18:02
R7jAkc , [url=http://saniqaqbkhbf.com/]saniqaqbkhbf[/url], [link=http://ewlgstribuud.com/]ewlgstribuud[/link], http://pnwokolkdbic.com/
十二月 27th, 2011 at 03:17
HGWoem vikogzvzahuv