hi all... i have a problem in jquery while checking the returned data from server.. pls anybody can resolve it?
this is my login jsp
i am checking the data that is returned from controller... if it is false then i have to display error page in jsp..
But eventhough if am getting true value from controller its printing the error message... that is the if part is not executing eventhough if i give correct login details...but when i put alert(data) inside post its showing true or false according to the login details entered... what is wrong in this? why if condition is not executing eventhough the content of data is true.. pls help me..
<%@ taglib prefix="c" uri="/WEB-INF/tlds/c.tld" %>
<html>
<head>
<title>PACTup</title>
<script type="text/javascript" src="././scripts/loginvalidate.js"></script>
<script type="text/javascript" src="././scripts/jquery.js"></script>
<link rel="stylesheet" href="././styles/login.css" type="text/css">
<script>
$(document).ready(function() {
//$("#login").css("border","1px solid black");
$("#loginForm").submit(function(event){
event.preventDefault();
var $form = $( this ),
email = $form.find( 'input[name="email"]' ).val(),
pass = $form.find( 'input[name="pass"]' ).val();
$.post('verify.htm',{email:email,pass:pass},function(data){
var content = $( data ).find( '#content' );
if(data == true){
return true;
}
else{
$("#error").text("Password is wrong, please try again").css("color","red").css("font-size","12").show();
return false;
}
});
});
});
</script>
</head>
<body>
<table width="100%">
<tr>
<td width="30%">
<center>
<form method="POST" action="verify.htm" id = "loginForm">
<table>
<tr>
<td>
<b><FONT FACE = "Comic Sans MS" size=3>Log in</FONT></b><br/>
<FONT FACE = "Comic Sans MS" size=1 color=" #ADA96E"> Please log in to continue </FONT>
</td>
</tr>
<tr>
<td>
<div id="error"> </div>
<br/>
<FONT FACE = "Comic Sans MS" size=1>
EMAIL
</FONT>
</td>
</tr>
<tr>
<td>
<input type="text" name="email" style="background-color: #FFF380">
</td>
</tr>
<tr>
<td>
<FONT FACE = "Comic Sans MS" size=1>
PASSWORD</FONT>
<FONT FACE = "Comic Sans MS" size=0.5 color="blue">
I forgot my password
</FONT>
</td>
</tr>
<tr>
<td>
<input type="password" name="pass" style="background-color: #FFF380;">
</td>
</tr>
<tr>
<td>
<input type="checkbox" value="Remember" /> 
<FONT FACE = "Comic Sans MS" size=1>
Remember Me
</FONT>
</td>
</tr>
<tr>
<td><input type="image" src="././images/login.jpg" value="submit" alt="submit"></td>
</tr>
</table>
</form>
</center>
</td>
<td width="30%">
<form name="signupForm" method="post" action="addUser.htm"
onSubmit="return signUpValidate()">
<table>
<tr>
<td>
<FONT FACE = "Comic Sans MS" size=3>
<b>New to PACTup?</b>
</FONT>
</td>
</tr>
<tr>
<td>
<FONT FACE = "Comic Sans MS" size=2 color=" #ADA96E">
A PACTup account is required to continue
</FONT>
</td>
</tr>
<tr>
<td><br/>
<FONT FACE = "Comic Sans MS" size=1>
FIRST NAME<br/>
</FONT>
<input type="text" name="firstName" /></td>
</tr>
<tr>
<td>
<FONT FACE = "Comic Sans MS" size=1>
LAST NAME<br/>
</FONT>
<input type="text" name="lastName" /></td>
</tr>
<tr>
<td>
<FONT FACE = "Comic Sans MS" size=1>
EMAIL<br/>
</FONT>
<input type="text" name="emailId" style="background-color: #FFF380;"/></td>
</tr>
<tr>
<td>
<FONT FACE = "Comic Sans MS" size=1>
PASSWORD<br/>
</FONT>
<input type="password" name="password"style="background-color: #FFF380;">
</td>
</tr>
<tr>
<td>
<FONT FACE = "Comic Sans MS" size=1>
RE-ENTER PASSWORD<br/>
</FONT>
<input type="password" name="reEnterPassword" style="background-color: #FFF380;"/>
</td>
</tr>
<tr>
<td><input type="checkbox" value="Discover new trips"/>
 
<FONT FACE = "Comic Sans MS" size=2>
Discover new trips<br>
</FONT>
     <FONT FACE = "Comic Sans MS" size=0.5 color=" #ADA96E">
with our weekly news letter
</FONT>
</td>
</tr>
<tr>
<td><br>
</td>
</tr>
<tr>
<td>
<FONT FACE = "Comic Sans MS" size=1 color=" #ADA96E">
By signing up, you agree to our terms of use
</FONT>
</td>
</tr>
<tr>
<td>
<br/>
<input type="image" src="././images/signup.jpg" value="submit" alt="submit"/>
</td>
</tr>
</table>
</form>
</td>
<td width="40%">
<form action="">
<table>
<tr>
<td>
<FONT FACE = "Comic Sans MS" size=2>
<b>Sign in with Facebook</b><br/>
</FONT>
<FONT FACE = "Comic Sans MS" size=0.8 color=" #ADA96E">
It's fast and easy
</FONT>
</td>
</tr>
<tr>
<td>
<a href=""><img src="././images/facebook.jpg"/></a>
</td>
</tr>
<tr>
<td><br/>
<b><FONT FACE = "Comic Sans MS" size=1.5>
Privacy
</Font></b>
<p><FONT FACE = "Comic Sans MS" size=1 color=" #ADA96E">
We don't share any of your PACTup<br/>
data with Facebook,or post anything<br/>
to your Facebook profile</FONT></p>
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
this is my controller
package com.pactup;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
public class LoginController extends SimpleFormController {
private LoginService loginService;
protected ModelAndView handleRequestInternal(HttpServletRequest request,HttpServletResponse response) throws IOException
{
HttpSession session1 = request.getSession();
String emailId = request.getParameter("email");
String password = request.getParameter("pass");
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
User user = loginService.getUserService(emailId,password);
if(user != null){
System.out.println(user.password);
session1.setAttribute("user", user.getFirstName());
out.println("true");
}
else{
request.setAttribute("authenticated","false");
System.out.println("invalid");
//return new ModelAndView("");
out.println("false");
}
out.close();
return null;
}
public void setLoginService(LoginService loginService){
this.loginService = loginService;
}
}