I have some problem to get the utf-8 string from PHP using jQuery $.load() utility function.
File 1: myrecord.txt, saved in utf-8 encoding using Notepad++
<p>你好, jQuery Ajax with load method.</p>.
File 2: myrecord.php, saved in utf-8 encoding using Notepad++
<?php
echo '<p>你好, jQuery Ajax with load method.</p>';
?>
File 3: loadTest.html, saved in utf-8 encoding using Notepad++
<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>
If I run loadTest.html as is, the result I got is correctly displayed as
你好, jQuery Ajax with load method.
However if I change the load method in file 3 to $('div').load('myrecord.php'), then the display changes to
???jQuery Ajax with load method.
What's wrong? Please help.
can you try loading that file using php file by using readfile function and that function should have header for utf-8 output?
header ('Content-type: text/html; charset=utf-8');
readfile('myrecord.txt');
In addition see if following URL can be of additional help: http://www.phpwact.org/php/i18n/utf-8
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With