ÓÉÓÚXMLHTTP²ÉÓõÄÊÇUnicode±àÂëÉÏ´«Êý¾Ý£¬¶øÒ»°ãÒ³Ãæ²ÉÓõÄÊÇgb2312,Õâ¾ÍÔì³ÉÏÔʾҳÃæʱ²úÉúÂÒÂë¡£¶øµ±ÔÚ»ñÈ¡Ò³ÃæʱµÄXMLHttp·µ»ØµÄÊÇutf-8±àÂ룬Õâ¾ÍÔì³ÉÁËÏÔʾ²úÉúÂÒÂë¡£...
ÓÉÓÚXMLHTTP²ÉÓõÄÊÇUnicode±àÂëÉÏ´«Êý¾Ý£¬¶øÒ»°ãÒ³Ãæ²ÉÓõÄÊÇgb2312,Õâ¾ÍÔì³ÉÏÔʾҳÃæʱ²úÉúÂÒÂë¡£¶øµ±ÔÚ»ñÈ¡Ò³ÃæʱµÄXMLHttp·µ»ØµÄÊÇutf-8±àÂ룬Õâ¾ÍÔì³ÉÁËÏÔʾ²úÉúÂÒÂë¡£
½â¾ö·½·¨Ö®Ò»¾ÍÊÇÔÚPHPÎļþÖÐÏÔʾÉùÃ÷ΪGB2312
header("Content-Type:text/html;charset=GB2312");
¶ø¶ÔÓÚ·¢Ë͵½·þÎñÆ÷µÄÖÐÎĽøÐÐתÂë¡£
ÈçÏÂ
$_POST["content"]=iconv("UTF-8","gb2312",$_POST["content"]);
Òò¶øÕâÑù¿ÉÒÔ½â¾öÂÒÂëÎÊÌâ
·½·¨¶þ£¬ÊǶ¼²ÉÓÃUTF-8±àÂë¡£ÕâÀï¾Í²»¶à˵ÁË
¸½²âÊÔÀý³Ì
¿Í»§¶Ë
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>ajax post test</title>
</head>
<body>
<div></div>
<script language="javascript">
/**
* ³õʼ»¯Ò»¸öxmlhttp¶ÔÏó
*/
function InitAjax()
{
var ajax=false;
try {
ajax = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
ajax = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
ajax = false;
}
}
if (!ajax && typeof XMLHttpRequest!='undefined') {
ajax = new XMLHttpRequest();
}
return ajax;
}
//ÔÚform ²âÊÔÒ³ÃæÄÚÓÐÒ»¸ö±íµ¥£¬Ò»¸öÏÔʾµÄ²ã
function sendData()
{
var msg=document.getElementById("msg");
var f=document.form1;
var c=f.content.value;
//½ÓÊÕÊý¾ÝµÄURL
var url="dispmsg.php";
var poststr="content="+c;
var ajax=InitAjax();
ajax.open("POST",url,true);
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
ajax.send(poststr);
ajax.onreadystatechange=function(){
if(ajax.readyState==4 && ajax.status==200){
alert("I got something");
msg.innerHTML=ajax.responseText;
}
}
}
</script>
<form>
<input type="text" size=10>
<input type="button" value="È·¶¨"><!--ÎÒÓÃsubmitʱ¾Í³ö´í-->
</form>
</body>
</html>
·þÎñÆ÷¶Ë
<?php
header("Content-Type:text/html;charset=GB2312");
if($_POST['content'])
{
$_POST["content"]=iconv("UTF-8","gb2312",$_POST["content"]);
print("ÄÚÈÝÊÇ".$_POST['content']);
}
else
{
print("ûÓÐÄÚÈÝ·¢ËÍ");
}
?>
¡¡