Correcting teacher:天蓬老师
Correction status:qualified
Teacher's comments:动画演示真好
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>用户登陆</title>
<script src="jquery-3.4.1.min.js"></script>
<script src="layer/layer.js"></script>
<style>
p{
background-color: #0C9A9A;
padding: 10px;
margin: 10px 50px 0 50px;
border-radius: 5px;
}
p input{
border-radius: 5px;
}
button{
background-color: #0a68b4;
padding: 10px;
margin: 10px 10px 0 50px;
border-radius: 5px;
}
</style>
</head>
<form action="">
<p>用户名:<input type="text" id="user" name="user"></p>
<p>密码:<input type="password" id="pass" name="pass"></p>
<button type="button" onclick="lpost()"> 登陆POST</button>
<button type="button" onclick="lget()"> 登陆GET</button>
</form>
<script>
function lpost() {
var user = $.trim($('input[name="user"]').val());
var pass = $.trim($('input[name="pass"]').val());
$.post('/1225/lpost.php',$('form').serialize(),function(res){
layer.alert(res.msg, {icon: res.icon});
if(res.code==0){
window.location.href = "/1225/user.html";
}
},'json');
}
function lget() {
var user = $.trim($('input[name="user"]').val());
var pass = $.trim($('input[name="pass"]').val());
$.get('/1225/lget.php',{user:user,pass:pass},function (res) {
layer.alert(res.msg, {icon: res.icon});
if(res.code==0){
window.location.href = "/1225/user.html";
}
},'json');
}
</script>
</body>
</html>
<?php
$user = $_POST['user'];
$pass = $_POST['pass'];
if ($user=='' || $pass==''){
$data = json_encode(
[
'code' => 400,
'msg' => '账号密码信息填写不完整!',
'icon' => 2
]
);
exit($data);
}
if ($user!='admin'){
$data = json_encode(
[
'code' => 1,
'msg' => '用户名错误',
'icon' => 5
]
);
exit($data);
}
if ($pass!='123456'){
$data = json_encode(
[
'code' => 2,
'msg' => '密码错误',
'icon' => 5
]
);
exit($data);
}
$data = json_encode(
[
'code' => 0,
'msg' => '你好' . $user . '欢迎━(*`∀´*)ノ亻!',
'icon' => 1
]
);
exit($data);
<?php
$user = $_GET['user'];
$pass = $_GET['pass'];
if ($user=='' || $pass==''){
$data = json_encode(
[
'code' => 400,
'msg' => '账号密码信息填写不完整!',
'icon' => 2
]
);
exit($data);
}
if ($user!='1'){
$data = json_encode(
[
'code' => 1,
'msg' => '用户名错误',
'icon' => 5
]
);
exit($data);
}
if ($pass!='1'){
$data = json_encode(
[
'code' => 2,
'msg' => '密码错误',
'icon' => 5
]
);
exit($data);
}
$data = json_encode(
[
'code' => 0,
'msg' => '你好' . $user . '欢迎━(*`∀´*)ノ亻!',
'icon' => 1
]
);
exit($data);