php接收ajax post資料編碼只能是gb2312

來源:互聯網
上載者:User
關鍵字 php post
phppost

各位大俠,我是一名初學者,用ajax post方式做的登入模組,提交資料到php,發現用gb2312編碼能正常接收資料,用utf-8編碼php端就沒有反應。我的各個網頁均已經設為utf-8編碼了,為什麼會這樣?還有用gb2312發送後,伺服器端能正常查詢資料庫,但是返回資料‘1’後,在js代碼裡面if與‘1’比較卻不相等,結果進入else代碼,是否也是編碼格式不相同的問題?煩請各位大俠幫忙指點迷津,謝謝!
js代碼如下:function loginphp(){

xmlhttp.onreadystatechange=function() {    if (xmlhttp.readyState==4 && xmlhttp.status==200) {      msg = xmlhttp.responseText;    if(msg == '1'){        document.getElementById("login").innerHTML="登入成功!";    }else if(msg=='2'){        document.getElementById("login").innerHTML="使用者名稱或密碼錯誤!";    }else{        document.getElementById("login").innerHTML=msg;    }}

}
xmlhttp.open("POST","application/reglog/login.php",true);
//xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");

xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=gb2312");
xmlhttp.send("email="+$('email').value+"&pwd="+$('pwd').value);
}

php代碼如下:
include_once "dbconn.php";
$sql = "select * from Basicinfo_user where user_email='".$_POST['email']."' and user_password='".$_POST['pwd']."'";
$num = $conne->getRowsNum($sql);
$conne->close_conn();
if($num == 1){
echo '1';
}else if($num == 0){
echo '2';
}else{
echo $conne->msg_error();
}
?>

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.