index.php
ajax.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>登录</title>
<script type="text/javascript" src="http://cdn.bootcss.com/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
帐号:<input type="text" id="account" />
<br><br>
密码:<input type="password" id="password" />
<br />
<input type="button" value="登录" id="btnlogin" />
<script type="text/javascript">
$(function(){
$("#btnlogin").click(function(){
$.ajax({
type:"post",
url:"ajax.php",
data:{account:$("#account").val(),password:$("#password").val()},
dataType:"json",
success:function(data){
if(data.type==1){
alert("登录成功");
}else{
alert("登录失败");
}
},
error:function(){
alert("请求异常");
}
});
});
});
</script>
</body>
</html>
|
<?php
header("Content-Type:text/html; charset=utf-8");
$account = $_POST['account'];
$password = $_POST['password'];
$result = array();
if ($account != '' && $password != '') {
//$row = $db->query("SELECT * FROM account where user = '".$account."' and password = '".$password."'");
$row = true;//这里去查数据库,假设这里返回true
if($row){
$result['type'] = 1;
$result['msg'] = '登录成功';
}else{
$result['type'] = 0;
$result['msg'] = '用户名或密码不正确';
}
} else {
$result['type'] = 0;
$result['msg'] = '参数传输不正确';
}
echo json_encode($result);
?>
|
The End


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)