Jquery load()乱码的解决办法:将两个页面的编码格式转换成utf8,在【test_text.php】开头加入一行代码【header("Content-type: text/html; charset=utf8");】。

本教程操作环境:windows7系统、jquery3.2.1版本,该方法适用于所有品牌电脑。 Jquery load()乱码的解决办法: jquery的字符集是utf-8,load方法加载完GB2312编码静态页面后,出现中文乱码. 这是jQueryAJAX.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title>通过jQuery AJAX改变这段文本</title>
<script type="text/javascript" src="js/jquery-1.11.3.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#btn1').click(function() {
$('#test').load('test_text.txt');
});
});
</script>
</head>
<body>
<h3 id="test">请点击下面的按钮,通过 jQuery AJAX 改变这段文本.</h3>
<button id="btn1" type="button">获得外部的内容</button>
</body>
</html>这是test_text.txt文件内容: 你好,这是新加载的文字! 解决办法: 方法:将两个页面的编码格式转换成utf8. 注明:如果要价在的文件是php文件:在test_text.php开头加入一行: header("Content-type: text/html; charset=utf8");相关免费学习推荐:javascript(视频)
以上就是Jquery load()乱码怎么解决的详细内容,更多请关注模板之家(www.mb5.com.cn)其它相关文章! |