在本地测试一切正常,但放在服务器上测试乱码,不明白!!!!!!!!!!!!!!!!

renqiang_888 2008-08-02 09:55:40
大家好,这个是书上的事例,在本地测试好好的,中文也不乱码,但放到服务器上就乱码了,请大家看一下
服务器地址:http://zzjxyh.cn/example/example1.html
example1.html内容如下:

<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache, must-revalidate" />
<meta http-equiv="expires" content="Thu, 01 Jan 1970 00:00:01 GMT" />
<meta http-equiv="expires" content="0" />
<script language="javascript">
var xmlHttp = "";
function createXML()//建立XMLHttp对象
{
xmlHttp = new window.XMLHttpRequest();
}
function handStateChange()
{
if(xmlHttp.readyState == 4)
{
if(xmlHttp.status == 200)
{
parseResult();
}
}
}
function parseResult()//解析请求结果
{
var serverResponse = document.getElementById("serverResponse");
if(serverResponse.hasChildNodes())
{
serverResponse.removeChild(serverResponse.firstChild);
}
serverResponse.appendChild(document.createTextNode(xmlHttp.responseText));
}
function createQueryString()//建立查询字符串
{
var FirstName = document.getElementById("FirstName").value;
var MiddleName = document.getElementById("MiddleName").value;
var Birthday = document.getElementById("Birthday").value;
return "FirstName=" + encodeURIComponent(FirstName) + "&MiddleName=" + encodeURIComponent(MiddleName) + "&Birthday=" + encodeURIComponent(Birthday);
}
function RequestGet()//处理get请求
{
createXML();
var url = "example1-get.php?date=" + new Date().getTime() + "&" + createQueryString();
xmlHttp.onreadystatechange = handStateChange;
xmlHttp.open("get",url,true);
xmlHttp.send(null);
}
function RequestPost()//处理post请求
{
createXML();
var url = "example1-post.php?date=" + new Date().getTime();
xmlHttp.onreadystatechange = handStateChange;
xmlHttp.open("post",url,true);
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
xmlHttp.send(createQueryString());
}
</script>
<body>
<h1>Enter your firstName,MiddloeName,and Birthday:</h1>
<table>
<tbody>
<tr>
<td>FirstName:</td>
<td><input type="text" id ="FirstName" /></td>
</tr>
<tr>
<td>MiddleName:</td>
<td><input type="text" id ="MiddleName" /></td>
</tr>
<tr>
<td>Birthday:</td>
<td><input type="text" id ="Birthday" /></td>
</tr>
</tbody>
</table>
<input type="button" value="get" onclick="RequestGet()"/><br>
<input type="button" value="post" onclick="RequestPost()"/><br>
<h2>Server Response</h2>
<div id="serverResponse"></div>
</body>

example1-get.php内容如下:

$string = "你好 " . iconv("utf-8","gb2312",$_GET['FirstName']) . iconv("utf-8","gb2312",$_GET['MiddleName']) . " 您的生日是: " . iconv("utf-8","gb2312",$_GET['Birthday']);
echo $string;

example1-post.php内容如下

$string = "你好 " . iconv("utf-8","gb2312",$_POST['FirstName']) . iconv("utf-8","gb2312",$_POST['MiddleName']) . " 您的生日是: " . iconv("utf-8","gb2312",$_POST['Birthday']);
echo $string;
...全文
514 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
renqiang_888 2008-08-02
  • 打赏
  • 举报
回复
是不是想骗我这个phper新手啊?
renqiang_888 2008-08-02
  • 打赏
  • 举报
回复
楼上说的没有一点道理
没有理论性,也没有说服性,
liguang0717 2008-08-02
  • 打赏
  • 举报
回复
一个原因是你的代码本身的编码格式问题 你查一下 你文件的编码格式 用 editplus 可以另存一下看看!!

另一个 你服务器和你本机的php环境
jlamp 2008-08-02
  • 打赏
  • 举报
回复
显示正常啊
renqiang_888 2008-08-02
  • 打赏
  • 举报
回复
在两个php文件头部加了:
Header("Content-type: text/html; charset=gb2312");
好了,却不知道为什么,在本地不加Header("Content-type: text/html; charset=gb2312");
也是好的,为什么到了服务器上,只有加上Header("Content-type: text/html; charset=gb2312");
才行,谢谢各位解释一下啦
renqiang_888 2008-08-02
  • 打赏
  • 举报
回复
天啊,不加:Header("Content-type: text/html; charset=UTF-8"); 在本地不是乱码,加了之后,
本地是乱码
务器上也是乱码了,
HW_zxc_002 2008-08-02
  • 打赏
  • 举报
回复
up
liguang0717 2008-08-02
  • 打赏
  • 举报
回复
你加上 这个 Header("Content-type: text/html; charset=UTF-8");
liguang0717 2008-08-02
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 renqiang_888 的回复:]
是不是想骗我这个phper新手啊?
[/Quote]


你这种垃圾 !! 我不提醒你能解决问题?

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧