<script type="text/javascript">
function ajax() {
//先声明一个异步请求对象
var xmlHttpReg = null;
if (window.ActiveXObject) {//如果是IE
xmlHttpReg = new ActiveXObject("Microsoft.XMLHTTP");
} else if (window.XMLHttpRequest) {
xmlHttpReg = new XMLHttpRequest(); //实例化一个xmlHttpReg
}
//如果实例化成功,就调用open()方法,就开始准备向服务器发送请求
if (xmlHttpReg != null) {
xmlHttpReg.open("get", "chuli.php?uid="+uid+"&pwd="+pwd, true);
xmlHttpReg.send(null);
xmlHttpReg.onreadystatechange = doResult(); //设置回调函数
}
//回调函数
//一旦readyState的值改变,将会调用这个函数,readyState=4表示完成相应
//设定函数doResult()
function doResult() {
if (xmlHttpReg.readyState == 4) {//4代表执行完成
if (xmlHttpReg.status == 200) {//200代表执行成功
var res = xmlHttpReg.responseText;
if (res == 'ok'){
alert('登录成功');
}else{
alert('登录失败');
};
}
}
}
}
</script>
function ajax() {
//先声明一个异步请求对象
var xmlHttpReg = null;
if (window.ActiveXObject) {//如果是IE
xmlHttpReg = new ActiveXObject("Microsoft.XMLHTTP");
} else if (window.XMLHttpRequest) {
xmlHttpReg = new XMLHttpRequest(); //实例化一个xmlHttpReg
}
//如果实例化成功,就调用open()方法,就开始准备向服务器发送请求
if (xmlHttpReg != null) {
xmlHttpReg.open("get", "chuli.php?uid="+uid+"&pwd="+pwd, true);
xmlHttpReg.send(null);
xmlHttpReg.onreadystatechange = doResult(); //设置回调函数
}
//回调函数
//一旦readyState的值改变,将会调用这个函数,readyState=4表示完成相应
//设定函数doResult()
function doResult() {
if (xmlHttpReg.readyState == 4) {//4代表执行完成
if (xmlHttpReg.status == 200) {//200代表执行成功
var res = xmlHttpReg.responseText;
if (res == 'ok'){
alert('登录成功');
}else{
alert('登录失败');
};
}
}
}
}
</script>
<?php
$uid=$_GET["uid"];
$pwd=$_GET["pwd"];
$pdo=new mysqli("localhost","root","","1");
!mysqli_connect_error ()or die("连接失败");
$sql="select uid from user where uid='{$uid}'";
$password=$pdo->query($sql);
if ($password == $pwd){
echo 'ok';
}else{
echo 'no';
}
$uid=$_GET["uid"];
$pwd=$_GET["pwd"];
$pdo=new mysqli("localhost","root","","1");
!mysqli_connect_error ()or die("连接失败");
$sql="select uid from user where uid='{$uid}'";
$password=$pdo->query($sql);
if ($password == $pwd){
echo 'ok';
}else{
echo 'no';
}