标签:ESS async 而不是 button control inpu orm action get
不比比,直接上代码
JSP页面,
<body>
<form action="" method="post" >
<input name="username" type="text" id="username" />
<input name="password" type="password" id="password" />
<button id="login" onclick="requestJson()" type="button">登录</button>
</form>
<script type="text/javascript">
function requestJson(){
var name =$("#username").val();
var pwd =$("#password").val();
if(name==""){
alert("用户名不能为空!");
return false;
}
else if(pwd==""){
alert("密码不能为空!");
return false;
}else{
$.ajax({
type:‘post‘,
url:‘login.do‘,
dataType:"json",//注意使用的是打他dataType,而不是Content-Type
async: true,
data:{username:name,password:pwd},
success:function(data){
if(data==null){
alert("没有这个用户!")
}
else{
alert("登录成功")
window.location.href ="index.jsp";
}
}
});
}
}
</script>
</body>
Controlle层
@RequestMapping("login")
@ResponseBody
public User loginto(User user) {
System.out.println("username:"+user.getUsername());
System.out.println("password:"+user.getPassword());
User users=userservice.login(user.getUsername(), user.getPassword());
System.out.println(users.getUsername());
return users;
}
}
标签:ESS async 而不是 button control inpu orm action get
原文地址:https://www.cnblogs.com/DIVEY/p/9921985.html