122 lines
4.8 KiB
HTML
122 lines
4.8 KiB
HTML
<!--
|
||
* @Descripttion:
|
||
* @version:
|
||
* @Author: Baron
|
||
* @Date: 2022-05-23 09:31:25
|
||
* @LastEditors: Andy
|
||
* @LastEditTime: 2024-06-25 11:15:19
|
||
-->
|
||
<!DOCTYPE html>
|
||
<html lang="en">
|
||
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta http-equiv="max-age" content="31536000">
|
||
<meta http-equiv="Pragma" content="public">
|
||
<meta http-equiv="Cache-control" content="public">
|
||
<meta http-equiv="Cache" content="public">
|
||
<meta name="viewport"
|
||
content="width=device-width, initial-scale=1, minimum-scale=0.01, maximum-scale=1, user-scalable=yes" />
|
||
<title>修改密码</title>
|
||
<link rel="stylesheet" href="css/style.css">
|
||
<script src="js/jquery-3.4.1.min.js"></script>
|
||
<script> src = "js/jsonid.js"</script>
|
||
|
||
</head>
|
||
|
||
<body>
|
||
<div class="contain">
|
||
<header>
|
||
<!-- <div><a href="screen_main.html"><返回</a></div> -->
|
||
</header>
|
||
<div class="box" id="box">
|
||
<h2>修改密码</h2>
|
||
<!-- <form action="login.html" method="post"> -->
|
||
<ul>
|
||
<li>
|
||
<label><span>*</span>原始密码:</label>
|
||
<input type="password" name="pwd" maxlength="10" placeholder="请输入原始密码" id="raw_pass">
|
||
</li>
|
||
<li>
|
||
<label><span>*</span>新密码:</label>
|
||
<input type="password" name="pwd" maxlength="10" placeholder="请输入新密码" id="new_pwd">
|
||
</li>
|
||
<li>
|
||
<label><span>*</span>确认新密码:</label>
|
||
<input type="password" name="pwdOk" maxlength="10" placeholder="确认密码必须与密码一致" id="pwdOK">
|
||
</li>
|
||
</ul>
|
||
<button name="submit" id="submit">提交</button><br>
|
||
<input type="reset" id="reset" value="取消"></button>
|
||
<!-- </form> -->
|
||
<div class="toast">
|
||
<span>密码不能为空</span>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<script>
|
||
$(function () {
|
||
var baseHost = document.location.origin
|
||
$('#submit').on('click', function () {
|
||
var rawPwd = $('#raw_pass').val()
|
||
var newPwd = $('#new_pwd').val()
|
||
var rePwd = $('#pwdOK').val()
|
||
var submit = {}
|
||
// submit.jsonid = json_id;
|
||
submit = new Object()
|
||
submit.log_in = new Object()
|
||
submit.log_in.type = 2
|
||
submit.log_in.pass = rawPwd
|
||
submit.log_in.new_pass = newPwd
|
||
console.log(JSON.stringify(submit))
|
||
if (!newPwd.trim().length || !rePwd.trim().length) {
|
||
$('.toast').css('display', 'flex')
|
||
setTimeout(function () {
|
||
$('.toast').css('display', 'none')
|
||
}, 2000)
|
||
return false
|
||
} else if (newPwd != rePwd) {
|
||
alert('新密码与确认密码不一致')
|
||
return false
|
||
}
|
||
//1.创建ajax对象
|
||
var xhr = new XMLHttpRequest()
|
||
xhr.open('post', baseHost + '/communication', true)
|
||
xhr.setRequestHeader('content-type', 'application/json')
|
||
xhr.send(JSON.stringify(submit))
|
||
xhr.onreadystatechange = function () {
|
||
if (xhr.readyState == 4 && xhr.status == 200) {
|
||
//1.服务器返回的json格式数据
|
||
var json = xhr.responseText
|
||
console.log(json)
|
||
/*2.
|
||
*通过eval方法将上面的数据转换成json格式,
|
||
*上面数据的所有双引号全部转换成单引号
|
||
*/
|
||
var result = eval("(" + json.replace(/"/g, "'") + ")")
|
||
/* 3.转换成json格式后可以通过对象的方式进行访问,既通过“.”的方式
|
||
* 判断从服务器返回值中return是否等于0
|
||
* 0:密码正确 1:密码错误
|
||
*/
|
||
if (result.led_protocol.log_in.return == 0) {
|
||
alert("修改密码成功!")
|
||
window.location.href = "/login.html"
|
||
return
|
||
} else {
|
||
alert("修改密码失败!")
|
||
return false
|
||
}
|
||
}
|
||
}
|
||
})
|
||
//单击取消按钮,跳转至登录页面
|
||
$("#reset").on('click', function () {
|
||
window.location.href = '/login.html'
|
||
})
|
||
})
|
||
</script>
|
||
|
||
</body>
|
||
|
||
</html>
|