摘要:function verfiy(user, result) { //1.创建request对象 var request = new XML
function verfiy(user, result) {
//1.创建request对象
var request = new XMLHttpRequest();
//2.监听响应状态
request.onreadystatechange = function(){
if (request.readyState === 4) { // 准备就绪
console.log(request.responseText);
result.innerHTML = request.responseText;
}
return false;
};
//3.设置请求参数
request.open('post','check.php',true);
//4. 设置头信息,将内容类型设置为表单提交方式(固定模板语法结构)
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
//4.发送请求
// 准备要提交的数据
var data = 'email=' + user.email + '&password=' + user.password;
request.send(data);
}check.php
<?php
$email = $_POST['email'];
$password = $_POST['password'];
$emailList = ['123@qq.com'];
$pwd = md5('123456');
if (!in_array($email, $emailList)) {
echo '<span style="color: red">邮箱不正确</span>';
} else if (md5($password) !== $pwd) {
echo '<span style="color: red">密码不正确</span>';
} else {
echo '<span style="color: blue">验证通过,正在跳转...</span>';
}
批改老师:查无此人批改时间:2019-05-17 09:24:05
老师总结:完成的不错,ajax的交互非常不错,可以让页面不刷新也能改变。继续加油。