Problem in getting response from server in jquery
- by Alvin
Hello, I'm using $.ajax(options) method to pass the request to server based on username and password, but whenever I try to print the response by XMLHttpRequest object when response gets successful, I'm getting an empty value.
$(document).ready(function(){
$("#form").submit(function(){
$.ajax({url:"Chat.jsp",type:"POST",data:$("#form").serialize(),success:function(request) {
alert(request.responseText); //This is displaying nothing
},error:function(){document.write("YOU can't");}});
});
});
This is what I'm doing in my servlets code after executing query:
try {
String user = request.getParameter("j_username");
String password = request.getParameter("j_password");
if(user != null && password != null) {
String query = "Select * from users where user_name="+"\'"+user+"\'"+"&& user_pass="+"\""+password+"\"";
DBCheck db= new DBCheck();
boolean b = db.doExecuteQuery(con.createStatement(),query);
response.setHeader("Cache-Control", "no-cache");
if(b) {
response.getWriter().println("Username already exits");
}
else {
response.getWriter().println("Username doesn't exit");
}
}
}
catch(SQLException ex) {
ex.printStackTrace();
}
}
May I know the problem, and how can I fix it?