Ajax 即“Asynchronous Javascript And XML”(异步 JavaScript 和 XML),是指一种创建交互式网页应用的网页开发技术。
<script src="js/jquery-1.10.2.js"></script> <link href="css/bootstrap.min.css" rel="stylesheet"> </head> <body> <script type="text/javascript"> $(document).ready(function () { $("#name").blur(function () { $.ajax({ type:"post", url:"lll", data:{"name":$("#name").val()}, async:false, success:function(msg){ if(msg=="N"){alert("用户不存在!")} }, error:function(){ alert(error); } }) }) }) </script>
<form class="form-horizontal" role="form" id="vForm" method="POST" action="list">
<div class="form-group ">
<label for="name" class="col-sm-4 control-label">姓 名</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="name" name="name" placeholder="请输入姓名">
</div>
</div>
<div class="form-group">
<label for="passowrd" class="col-sm-4 control-label">密 码</label>
<div class="col-sm-4">
<input type="password" class="form-control" id="password" name="password" placeholder="请输入密码">
</div>
</div>
<div class="form-group">
<div class="col-sm-4 col-sm-offset-3 control-label ">
<button type="button" class="btn btn-info" id="bu">登录</button>
<a href="register" class="btn btn-info">注册</a>
</div>
</div>
</form>
后台
@RequestMapping("/lll") public String testlll(String name,HttpServletResponse response) { System.out.println(name);
String msg = "N"; if(name.equals("user"){
msg = "Y"
}
try { PrintWriter out=response.getWriter(); out.write(msg); out.flush();//这句千万不能少 } catch (IOException e) { e.printStackTrace(); } return msg; }
功能很简单就是比较输入框的数据和后台数据是否相同,延伸一下实现的功能就很多了,比如登录验证,注册验证等