很抱歉如果我问了一个愚蠢的问题,但我真的需要解决方案。我正在使用ajax请求一些数据,脚本是:
<!DOCTYPE html>
<html>
<head>
<script>
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
$url='http://localhost/path/to/the/php/script';
xmlhttp.open("GET",$url,true);
xmlhttp.send();
}
</script>
</head>
<body>
<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>
</body>
</html>
这是我的PHP脚本
<?php
$sqlurl='/path/to/my/file';
if(file_exists($sqlurl))
{
$sqlitedata= file_get_contents($sqlurl);
echo $sqlitedata;
}
else {
echo 'the file is not available right now';
}
?>
现在的问题是,我的文件中的数据是以UTF-8格式存储的,但是当我尝试通过ajax获取它时,得到的是一系列问号(??????)。我该如何在请求数据时保持原始格式不变?