使用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;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

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <font color="" face="" size=""> <span style="">