<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>注册页面</title>
<link rel="stylesheet" href="css/normalize.min.css">
<link rel="stylesheet" href="css/style.css">
<script src="js/jquery.min.js"></script>
<script src="js/script.js"></script>
</head>
<body>
<div id="formContainer" class="dwo">
<div class="formLeft">
<img src="images/avatar.png" height="105" width="100"/>
</div>
<div class="formRight">
<!-- Forgot password form -->
<form id="forgot" class="otherForm">
<header>
<h1>忘记密码</h1>
<p>输入邮箱找回密码</p>
</header>
<section>
<label>
<p>邮箱</p>
<input type="email" placeholder=" ">
<div class="border"></div>
</label>
<button type="submit">发送邮件</button>
</section>
<footer>
<button type="button" class="forgotBtn">返回</button>
</footer>
</form>
<!-- Login form -->
<form id="login">
<header>
<h1>欢迎回来</h1>
<p>请先登录</p>
</header>
<section>
<label>
<p>用户名</p>
<input type="text" name="username" placeholder=" ">
<div class="border"></div>
</label>
<label>
<p>密码</p>
<input type="password" name="password" placeholder=" ">
<div class="border"></div>
</label>
<button onclick="login()">登 录</button>
</section>
<footer>
<button type="button" class="forgotBtn">忘记密码?</button>
<button type="button" class="registerBtn">新用户?</button>
</footer>
</form>
<!-- Register form -->
<form id="register" class="otherForm">
<header>
<h1>用户注册</h1>
<p>注册后享受更多服务</p>
</header>
<section>
<label>
<p>用户名</p>
<input type="text" name="username" placeholder=" ">
<div class="border"></div>
</label>
<label>
<p>邮箱</p>
<input type="email" placeholder=" ">
<div class="border"></div>
</label>
<label>
<p>密码</p>
<input type="password" placeholder=" ">
<div class="border"></div>
</label>
<label>
<p>重复密码</p>
<input type="password" placeholder=" ">
<div class="border"></div>
</label>
<button onclick="register()">注 册</button>
</section>
<footer>
<button type="button" class="registerBtn">返回</button>
</footer>
</form>
</div>
</div>
</body>
<script>
//登录
function login() {
$.ajax({
type: "post", //数据提交方式(post/get)
url: "/login", //提交到的url
async: false,
data: $('#login').serialize(),
dataType: "json",//返回的数据类型格式
success: function (r) {
if (r.code == 200) {
let tokens = JSON.stringify(r.data.tokens)
let user = JSON.stringify(r.data.user)
localStorage.setItem("tokens", tokens)
localStorage.setItem("user", user);
window.location.href = "../index.html";
} else {
alert(r.code + r.msg);
}
},
error: function () {
alert("错误")
}
});
}
</script>
</html>
不知道怎么回事,登录就刷新当前页面,就是不跳转,之前加alert也看到走到 window.location.href = "../index.html";这句的上一行了。
这是我在jquery插件库里找到注册页面,登录方法的ajax是我自己写到,他用的是jquery1.1的貌似,不知道是不是这个问题,但是我用jquery3.6.0的他的页面又不好使