利用ajax异步校验用户名
2018-03-14 14:30
337 查看
1.在需要验证的用户名框里面增加onblur焦点移除事件<td class="datalist_right" width="140"><span class='red_text'>*</span>登录账号:</td>
<td class="datalist_left" width="150px"><s:textfield name="person.loginNo" id="loginNo" cssStyle="width:99%" onblur="checkName();"/></td>2.定义ajax异步传值给后台(这里以弹框为例) function checkName(){
$.ajax({
type: "post",
url:"/system/person/checkName.action",
data: {username: $("#loginNo").val()},
success: function(msg){ //msg为后台处理结果后返回的信息
if("success"==msg){
alert("用户名已存在");
return true;
}
},
error: function(){
alert("调用异常");
}
});
}3.前台值已传入后台方法(/system/person/checkName.action)public void checkName() throws Exception{
String username = getRequest().getParameter("username");
if(perSer.checkName(username)){
toClient("success");
}
}4.toClient为已封装方法,后台主要查询数据库是否存在相同账户 protected void toClient(String content) throws Exception
{
content = content ==null ? "":content;
// 使用当前应用的编码
String encoding = "utf-8";
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding(encoding);
PrintWriter pw = response.getWriter();
pw.print(content);
pw.flush();
}
<td class="datalist_left" width="150px"><s:textfield name="person.loginNo" id="loginNo" cssStyle="width:99%" onblur="checkName();"/></td>2.定义ajax异步传值给后台(这里以弹框为例) function checkName(){
$.ajax({
type: "post",
url:"/system/person/checkName.action",
data: {username: $("#loginNo").val()},
success: function(msg){ //msg为后台处理结果后返回的信息
if("success"==msg){
alert("用户名已存在");
return true;
}
},
error: function(){
alert("调用异常");
}
});
}3.前台值已传入后台方法(/system/person/checkName.action)public void checkName() throws Exception{
String username = getRequest().getParameter("username");
if(perSer.checkName(username)){
toClient("success");
}
}4.toClient为已封装方法,后台主要查询数据库是否存在相同账户 protected void toClient(String content) throws Exception
{
content = content ==null ? "":content;
// 使用当前应用的编码
String encoding = "utf-8";
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding(encoding);
PrintWriter pw = response.getWriter();
pw.print(content);
pw.flush();
}
相关文章推荐
- 利用ajax异步post方式校验验证码
- Ajax完成用户名的异步校验
- 利用ajax异步校验验证码
- 使用AJAX完成用户名是否存在异步校验:
- 利用ajax异步校验验证码(转)
- 异步校验用户名是否存在(AJAX)
- 使用AJAX完成用户名是否存在异步校验
- SSH网上商城之使用ajax完成用户名是否存在异步校验
- Ajax异步请求-校验用户名的唯一性
- 力所能及之springmvc+ajax+jquery+json实现登录异步校验用户名是否存在
- JQ对用户名异步校验(JQ的AJAX)
- 【JAVAWEB学习笔记】22_ajax:异步校验用户名和站内查询
- 案例:Ajax异步校验用户名是否存在
- jquery easyUI中ajax异步校验用户名
- ssh项目+jqueryeasyUI中ajax异步校验用户名
- 关于ajax+jsp实现异步校验用户名是否存在的实例(.txt文本)
- 使用AJAX完成用户名是否存在异步校验
- SSH网上商城---使用ajax完成用户名是否存在异步校验
- 【项目实战】---使用ajax完成用户名是否存在异步校验
- 利用Ajax异步验证用户名是否已被注册