网络上有很多用ajax实现前后台调用数据的例子,但是好多没有后台文件,这样让初学者学习的时候感觉很无助,不知道后台文件是什么样的,更不会写后台文件,所以今天整理一份前端html(jquery)、php文件及接口文档的例子
html文件需要放到服务器(WWW)下,register.php和registerCode.php文件只需要和html文件同级目录即可,接口文档即后台人员给前端人员的参考文档
主要用到jquery中的$.ajax()方法,验证的内容比较简单,大神们勿喷,仅帮助初学者更深刻的了解ajax使用方法
<!doctype html>
<html lang="en"><head>
<meta charset="UTF-8">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
ul{
list-style: none;
}
ul li{
line-height: 40px;
}
.tips{
margin-top: 30px;
}
.tips>p{
width: 300px;
background: red;
text-align: center;
line-height: 40px;
color:#fff;
display: none;
}
#verity,#submit{
width: 120px;
line-height: 40px;
background: red;
color: #fff;
border: none;
border-radius: 5px;
}
input{
outline: none;
}
input.disabled{
background: #ccc !important;
}
</style>
</head>
<body>
<div class="register">
<ul>
<li>
<label for="username">用户名:</label>
<input type="text" id="username" />
</li>
<li>
<label for="pass">密码:</label>
<input type="password" id="pass"/>
</li>
<li>
<label for="repass">确认密码:</label>
<input type="password" id="repass"/>
</li>
<li>
<label for="mobile">手机号:</label>
<input type="text" id="mobile"/>
</li>
<li>
<label for="code">验证码:</label>
<input type="text" id="code"/>
<input type="button" value="获取验证码" id&