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();
}
?>