Home > Backend Development > PHP Tutorial > php接收ajax post数据编码只能是gb2312

php接收ajax post数据编码只能是gb2312

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-02 11:33:34
Original
1209 people have browsed it

phppost

各位大侠,我是一名初学者,用ajax post方式做的登录模块,提交数据到php,发现用gb2312编码能正常接收数据,用utf-8编码php端就没有反应。我的各个网页均已经设为utf-8编码了,为什么会这样?还有用gb2312发送后,服务器端能正常查询数据库,但是返回数据‘1’后,在js代码里面if与‘1’比较却不相等,结果进入else代码,是否也是编码格式不相同的问题?烦请各位大侠帮忙指点迷津,谢谢!
js代码如下:function loginphp(){

<code>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;    }}</code>
Copy after login

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

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template