Skip to content

Login page using jquery ajax with asp.net ?

Prasad Bhagat

Prasad Bhagat

Asked Nov 9, 2015, 12:41 AM EST1 answer
Share
LinkedInX
Dear all,
 
i want create a login page after giveing username and password check it from database and redirect to welcome page using jqueary ajax with asp.net .
please ma new to this jqueary ajax am not understanding single one also ..i am seaching in google getting lots of examples but am not understading please
give me a simple example ..with jqueary ajax with asp.net..

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    JavaScript
    var username = $("#txtusername").val();
    var password = $("txtpassword").val();
    $.ajax({
    type: "POST",
    url: "login.aspx",
    data: "action=" + "Login" + "&username=" + username + "&password="  +password,
    JavaScript
                success: function (msg) {
                    if (msg == "true") {
    window.location.href = 'Index.aspx';
                    }else{
       alert("Username or password is incorrect");
    }
                }
            });
    c# Code in Page load funtion   
    Code
    if (Request["action"] == "login")
                {
                    LoginUser();
                    Response.End();
                }
     
    Java
    private void LoginUser()
            {
    
                    string userName = Request["userName"];
                    string password = Request["password"];
    Login obj = query here... get record password and username where they are same.
                    if (obj != null)
                    {
                        Response.Write("true");
                    }
                    else
                    {
                        Response.Write("notPresent");
                    }
    
    
    
    
            }
    0