用jquery寫的校驗用戶名
阿新 • • 發佈:2019-02-11
else req info turn null == action ring jquery
$(function(){ $("input[name=‘username‘]").blur(function(){ var uname = $(this).val(); console.log(uname); console.log(uname==""); if (uname=="") { $("#span1").html("用戶名不能為空!"); }else{ $.post("${pageContext.request.contextPath}/userAction_UserExists", {"uname":uname}, function(data){ $("#span1").html(data); }, ‘json‘ ); } }); });
後端java代碼:
private String uname; public String UserExists() throws IOException { log.info(uname); if ("admin".equals(uname)) { String s = "[{\"info\":\"用戶名不存在!\"}]"; String json = JSONArray.fromObject(s).toString(); ServletActionContext.getResponse().getWriter().write(json); }else { } return null; } public void setUname(String uname) { this.uname = uname; }
只給出了js代碼和java代碼,html代碼太亂了不好意思往上貼
用jquery寫的校驗用戶名