Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 141456

how to compare response from jsp page to ajax page?

$
0
0

i am comparing the response i got from jsp page to ajax . i want to perform if out.print() print success message so i want to perform action in success ajax function . i am comparing data . but it is not working . i always go to else section . i am new in ajax . can please help me out with this problem.

      $.ajax({
    url: "login.jsp",
    //datatype: "text",
    type: "POST",

    data: datatopost,
    success: function(data){

        if(data.search("success")!=-1){ 
            console.log(data.data);
              $('#loginmessage').html(data);
              $("#spinner").css("display", "none");
            //show message
            $("#loginmessage").slideDown();
          //  window.location = "mainpageloggedin.jsp";
         //$('#loginmessage').text(data);  
        }else{
       // $('#loginmessage').text(data);   
            //hide spinner
            //window.location = "mainpageloggedin.jsp";
            $("#spinner").css("display", "none");
            //show message
            $("#loginmessage").slideDown();
        }
    },
    error: function(){
        $("#loginmessage").html("<div class='alert alert-danger'>There was an error with the Ajax 
    Call. Please try again later.</div>");
        //hide spinner
        $("#spinner").css("display", "none");
        //show message
        $("#loginmessage").slideDown();

    }

});

jsp code...

<%@ include file="connection.jsp"%>
 <%
 String email=request.getParameter("loginemail");
 String loginpass=request.getParameter("loginpassword");
    ResultSet rs=st.executeQuery("select password from users where email='"+email+"'");
 if(rs.next())
 {
 String password1=rs.getString(1);
 if(password1.equals(loginpass))
  {
    session.setAttribute("email",email);
    out.print("success");

   }
    else
  {
    out.print("invalid combination of email and password");
    }
 } else
     {out.print("this account does not have information");
   }

   %>

Viewing all articles
Browse latest Browse all 141456

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>