javaWEB登录ajax传值

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
function testLogin() {
//获取页面上的数据
var no = $("#eno").val();
var name = $("#ename").val();
$.ajax({
//发送ajax请求
//url:请求服务器地址
//data:发送给服务器的数据
//msg:服务器回传的数据
url : "LoginServlet",
data :{
empno:no,
empname:name,
},
type:"post",
success:function(msg){
alert(msg)
if (msg=="ok") {
location.href="main.jsp"
}else {
alert("用户名密码错误");
}
}
});
}
</script>
</head>
<body>
<table>
<tr>
<td>工号</td>
<td><input type="text" id="eno"></td>
</tr>

<tr>
<td>密码</td>
<td><input type="text" id="ename"></td>
</tr>
<tr>
<td colspan="2">
<button onclick="testLogin()">登录</button>
</td>
</tr>

</table>


</body>
</html>

猜你喜欢

转载自www.cnblogs.com/chenligeng/p/9204330.html