这是我的ajax部分
$.ajax({
type:"GET",
data: 'name='+ value,
url: "master/Valid.jsp",
success: function(status){
if(status)
return true;
else
return false;
}
});
这是我的valid.jsp页面
<%
String s1 = request.getParameter("name");
int check = new DBDepartment().addDepartment(s1, 1);
if(check==1)
return false; //in this line it shows error
%>
我们如何发送返回值为true或false。
答案 0 :(得分:0)
不确定$ .ajax,但尝试使用$ .post或$ .get
// HTML
<form method="get" action="valid.jsp" id="login">
<p>
<label for="username">Username:</label>
<input type="text" name="username" id="username">
</p>
<p>
<label for="password">Password: </label>
<input type="text" name="password" id="password">
</p>
<p>
<input type="submit" name="button" id="button" value="Submit" >
</p>
</form>
// AJAX
$('#login').submit(function(evt) {
evt.preventDefault();
var formData = $(this).serialize();
$.get('valid.jsp',formData,processData);
function processData(data) {
if (data.trim()=='pass') {
$('#formwrapper').html('<p>You have successfully logged on!</p>');
} else {
if (! $('#fail').length) {
$('#formwrapper').prepend('<p id="fail">Incorrect login information. Please try again</p>');
}
}
} // end processData
});
<%
String user = request.getParameter("username");
String pass = request.getParameter("password");
if(user.equalsIgnoreCase("007")&&pass.equals("secret")){
out.print("pass");
}else{
out.print("fail");
}
%>