$(function() {
$("#loginBtn").click(function() {
var username = $("#userName").val();
var id_card = $("#id_card").val();
$.ajax({
type:"POST",
url:"login.do",
data:{"userName" : username,"id_card" : id_card},
dataType:"json",
success:function(data){
if(data=="success"){
window.location.href = "index.jsp";
}else{
window.location.href = "login.jsp";
}
}
});
});
});
后台控制层
@RequestMapping(value="/login.do")
@ResponseBody
public String loginAccount(String userName,String id_card,HttpServletRequest request,HttpServletResponse response) throws IOException{
String login = classificationService.login(userName, id_card);
String re;
response.setContentType("text/html;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
if(login!=null){
re="success";
System.out.println(re);
}else{
re="login";
System.out.println(re);
}
return re;
}