日期:2014-05-17 浏览次数:20696 次
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(function() {
$('#sum').click(function() {
var res = true;
$.ajax( {
type : 'post',
url : 'logins.action',
data : {
'username' : $('#username').val(),
'password' : $('#password').val()
},
async : false,
success : function(returnType) {
if (returnType == '正确') {
alert(returnType);
res = true;
} else {
alert(returnType);
res = false;
}
},
datatype : 'text'
})
return res;
});
});
</script>
</head>
<body>
<form action="login.action">
登录:
<br />
姓名:
<input type="text" name="username" id="username" />
<br />
密码:
<input type="password" name="password" id="password" />
<br />
<input type="submit" value="验证" id="sum" />
</form>
</body>
</html>
success : function(returnType) { if (returnType == '正确') { alert(returnType); res = true; } else { alert(returnType); res = false; } }, datatype : 'text'你这个代码在这里有点问题,你的后台java代码使用的是struts2把。ajax验证,