标签: 使用ajax验证信息 controller @RequestMapping(/check)public Str
标签:
使用ajax验证信息controller
@RequestMapping("/check") public String check(String username, String password) { String msg = ""; if (username != null) { if ("admin".equals(username)) { msg = "ok"; } else { msg = "用户名错误"; } } if (password != null) { if ("123456".equals(password)) { msg = "ok"; } else { msg = "暗码错误"; } } return msg; }username,password输入框和提示
<p> 用户名:<input type="text" id="username" onblur="checkid()"> <span id="userInfo"></span> </p> <p> 暗码:<input type="password" id="password" onblur="checkpwd()"> <span id="pwdInfo"></span> </p>checkid和checkpwd
<script> function checkid() { $.post({ url: "${pageContext.request.contextPath}/check", data: {'username': $("#username").val()}, success: function (data) { if (data.toString() === 'ok') { $("#userInfo").css("color", "green"); } else { $("#userInfo").css("color", "red"); } $("#userInfo").html(data); } }) } function checkpwd() { $.post({ url: "${pageContext.request.contextPath}/check", data: {'password': $("#password").val()}, success: function (data) { if (data.toString() === 'ok') { $("#pwdInfo").css("color", "green"); } else { $("#pwdInfo").css("color", "red"); } $("#pwdInfo").html(data); } }) } </script>页面效果
使用ajax验证信息
,温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/31010.html
- 上一篇:新浪显得太官方
- 下一篇:只能是当前的文件进行越权删除来利用