Heim  >  Artikel  >  Web-Frontend  >  解决Jquery load()加载GB2312页面时出现乱码的两种方案_jquery

解决Jquery load()加载GB2312页面时出现乱码的两种方案_jquery

WBOY
WBOYOriginal
2016-05-16 17:22:561208Durchsuche

问题描述:jquery的字符集是utf-8,load方法加载完GB2312编码静态页面后,出现中文乱码。

a.php

复制代码 代码如下:


点击加载b页面


b.php
复制代码 代码如下:

echo "我这里面有中文";
?>

解决方案:

方法一:将两个页面的编码格式转换成utf8

方法二:在b.php开头加入一行:header("Content-type: text/html; charset=gb2312");

a.php改为(不改应该也行):
复制代码 代码如下:

$("#job").load('b.php',function(rText){
$("#job").html(rText);
});

问题解决。

如果使用的是smarty模板引擎,a.php加载的是模板b.html,那么要先使php标签可用,然后在b.html中加入:{php}header("Content-type: text/html; charset=gb2312");{/php}
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn