AJax¼¼Êõ

ajax+phpÖÐÎÄÂÒÂëµÄ½â¾ö

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2017-06-11 17:05 ÎÒÒªÆÀÂÛ( )

ÓÉÓÚXMLHTTP²ÉÓõÄÊÇUnicode±àÂëÉÏ´«Êý¾Ý£¬¶øÒ»°ãÒ³Ãæ²ÉÓõÄÊÇgb2312,Õâ¾ÍÔì³ÉÏÔʾҳÃæʱ²úÉúÂÒÂë¡£¶øµ±ÔÚ»ñÈ¡Ò³ÃæʱµÄXMLHttp·µ»ØµÄÊÇutf-8±àÂ룬Õâ¾ÍÔì³ÉÁËÏÔ

ÓÉÓÚ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("ûÓÐÄÚÈÝ·¢ËÍ");
}
?>

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
  • WebÇ°¶ËÃæÊÔ¼¼ÇÉ£ºÃæÊÔºãÉúµç×ÓWebÇ°¶Ë¿ª·¢¹¤³Ìʦ¾­Ñé

    WebÇ°¶ËÃæÊÔ¼¼ÇÉ£ºÃæÊÔºãÉúµç×ÓWebÇ°¶Ë¿ª·¢¹¤³Ìʦ¾­Ñé

    2017-06-09 17:01

  • Hybrid--WebViewÖÐʹÓÃAjax£¬webviewajax

    Hybrid--WebViewÖÐʹÓÃAjax£¬webviewajax

    2017-06-08 13:00

  • ¹ØÓÚѧϰajaxµÄ×ܽá

    ¹ØÓÚѧϰajaxµÄ×ܽá

    2017-06-08 12:04

  • AjaxÉîÈëѧϰ±Ê¼Ç

    AjaxÉîÈëѧϰ±Ê¼Ç

    2017-06-08 12:03

ÍøÓѵãÆÀ
¦