Problem in getting response from server in jquery

Posted by Alvin on Stack Overflow See other posts from Stack Overflow or by Alvin
Published on 2010-05-23T13:28:13Z Indexed on 2010/05/23 13:30 UTC
Read the original article Hit count: 240

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about AJAX