账号显示检测失败是什么原因
来源:2-10 脚本
May_seven
2020-08-17 00:12:23
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>登录注册</title>
<link type="text/css" rel="stylesheet" href="style.css">
</head>
<body>
<div id="box">
<p class="title">
<span id="login">登 录</span>
<span id="register">注 册</span>
</p>
<div id="number">
<span>+86</span>
<input type="text" name="num" id="num" placeholder="请输入注册手机号"/>
<i id="user_icon"></i>
<p id="userInfo" class="info"></p>
</div>
<div id="password">
<input type="text" name="pwd" id="pwd" placeholder="请设置密码"/>
<i id="pwd_icon"></i>
<p id="pwdInfo" class="info"></p>
</div>
<button id="btn">注 册</button>
</div>
</div>
<script type="text/javascript" src="ajax.js"></script>
<script type="text/javascript">
var num=document.getElementById("num"),
userInfo=document.getElementById("userInfo")
user_icon=document.getElementById("user_icon"),
pwd_icon=document.getElementById("pwd_icon"),
pwd=document.getElementById("pwd"),
btn=document.getElementById("btn"),
numFlag=false,
pwdFlag=false,
noRepeat=false;
function checkUser(){
var pattern=/^1[3578]\d{9}$/,
numVal=num.value;
if(!pattern.test(numVal)){
userInfo.innerHTML="手机号码无效";
user_icon.className="no";
}else{
numFlag=true;
//ajax请求
$.ajax({
url:"http://localhost/ajax/register/isRepeat.php",
// method:"post",
// async:true,
data:{username:numVal},
success:function(data){
if(data.code==1){
userInfo.innerHTML="";
user_icon.className="ok";
noRepeat=true;
}else if(data.code==0){
userInfo.innerHTML=data.msg;
user_icon.className="no";
}else{
userInfo.innerHTML="检测失败,请重试";
user_icon.className="no";
}
}
});
}
}
function checkPwd(){
var pattern=/^\w{5,12}$/,
pwdVal=pwd.value;
if(!pattern.test(pwdVal)){
pwdInfo.innerHTML="请输入5-12位数字、字母或下划线";
pwd_icon.className="no";
}else{
pwdInfo.innerHTML="";
pwd_icon.className="ok";
pwdFlag=true;
}
}
function register(){
var num_val=num.value,
pwd_val=pwd.value;
if(numFlag==true && pwdFlag==true && noRepeat==true){
$.ajax({
url:"http://localhost/ajax/register/register.php",
method:"post",
async:true,
data:{username:num_val,userpwd:pwd_val},
success:function(data){
alert("注册成功,请登录!");
},
error:function(){
alert("注册失败,请重试!");
}
})
}
}
//绑定函数、检测用户有效性及是否重复注册
num.addEventListener("blur",checkUser,false);
//绑定函数、检测密码有效性
pwd.addEventListener("blur",checkPwd,false);
//绑定函数、注册
btn.addEventListener("click",register,false);
</script>
</body>
</html>
var $ = {
ajax:function(options){
var xhr = null, // XMLHttpRequest对象
url = options.url, // url地址
method = options.method || 'get', // 传输方式,默认为get
async = typeof(options.async) === "undefined"?true:options.async,
data = options.data || null, // 参数
params = '',
callback = options.success, // ajax请求成功的回调函数
error = options.error;
// 将data的对象字面量的形式转换为字符串形式
if(data){
for(var i in data){
params += i + '=' + data[i] + '&';
}
params = params.replace(/&$/,"");
}
// 根据method的值改变url
if(method === "get"){
url += '?'+params;
}
if(typeof XMLHttpRequest != "undefined"){
xhr = new XMLHttpRequest();
}else if(typeof ActiveXObject != "undefined"){
// 将所有可能出现的ActiveXObject版本放在一个数组中
var xhrArr = ['Microsoft.XMLHTTP','MSXML2.XMLHTTP.6.0','MSXML2.XMLHTTP.5.0','MSXML2.XMLHTTP.4.0','MSXML2.XMLHTTP.3.0','MSXML2.XMLHTTP.2.0'];
// 遍历创建XMLHttpRequest对象
var len = xhrArr.length;
for(var i = 0;i<len;i++){
try{
// 创建XMLHttpRequest对象
xhr = new ActiveXObject(xhrArr[i]);
break;
}
catch(ex){
}
}
}else{
throw new Error('No XHR object availabel.');
}
xhr.onreadystatechange = function(){
if(xhr.readyState === 4){
if((xhr.status >=200 && xhr.status <300) || xhr.status === 304){
callback && callback(JSON.parse(xhr.responseText))
}else{
error && error();
}
}
}
// 创建发送请求
xhr.open(method,url,async);
xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xhr.send(params);
}
}
文件位置:D:\phpStudy\PHPTutorial\WWW\ajax\register\isRepeat.php
1回答
好帮手慕言
2020-08-17
同学你好,使用同学提供的代码放到源码中测试,url改为正确的路径,是可以注册成功的
同学可以下载源码,把自己的代码放到源码中测试下,祝学习愉快~
相似问题