我在使用 jQuery $.load() 实用程序函数从 PHP 获取 utf-8 字符串时遇到了一些问题。
文件 1:myrecord.txt,使用 Notepad++ 以 utf-8 编码保存
<p>你好, jQuery Ajax with load method.</p>.
文件 2:myrecord.php,使用 Notepad++ 以 utf-8 编码保存
<?php
echo '<p>你好, jQuery Ajax with load method.</p>';
?>
文件 3:loadTest.html,使用 Notepad++ 以 utf-8 编码保存
<html>
<head>
<title>Load Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js">
</script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$('div').load('myrecord.txt');
});
</script>
</head>
<body>
<div></div>
</body>
</html>
如果我按原样运行 loadTest.html,我得到的结果将正确显示为
你好,带有加载方法的jQuery Ajax。
但是,如果我将文件 3 中的加载方法更改为 $('div').load('myrecord.php'),则显示更改为
???带有加载方法的jQuery Ajax。
怎么了?请帮忙。