0

I've got an Ajax call for log in here is the code:

//if MOUSE class is clicked
$('.mouse').click(function () {
    //get the form to submit and return a message
    //how to call the function 

    var name = $('#name').val();
    var pwd2 = $('#pwd2').val();
    $.ajax({
    type:"POST",               
     url: "http://localhost:51870/code/Login.aspx",
     data: "{ 'name':'" + $('#name').val() + "', 'pwd':'" + $('#pwd2').val() + "' }",
     contentType: "application/json; charset=utf-8",
     dataType: "json",
     context: document.body, 
     success: function () {
        //$(this).addClass("done");
        $(this).hide();
         $('.mouse, .window').hide();
                         }
});

});

the problem is I can't seem to catch name and pwd variables in Login page's preinit event or page load event here is the code in c#:

 protected void Page_PreInit(object sender, EventArgs e)
{
    //taking javascript argument in preinit event
    //from here I'll have to build the page for specific lookbook
    var name = Request.QueryString["name"];
    var pwd = Request.QueryString["pwd"];

}

protected void Page_Load(object sender, EventArgs e)
{
    var name = Request.QueryString["name"];
    var pwd = Request.QueryString["pwd"];
    SignIn(name);
}

I can't seem to get username name and password in c# side, help is appreciated.

Here is my final javascript code c# code remains the same:

<script type="text/javascript">

        $(document).ready(function () {    
 //if MOUSE class is clicked
            $('.mouse').click(function () {

                var name = $('#name').val();
                var pwd = $('#pwd').val();
                $.ajax({
               url: "http://localhost:51870/code/Login.aspx?name="+ name +"&pwd="+pwd,
               context: document.body, 
               success: function () {
                    //$(this).addClass("done");
                    $(this).hide();
                     $('.mouse, .window').hide();
                                     }
            });

            });

     });
</script>

Thanks Zachary

1 Answer 1

1

Your sending JSON data to the Login page but your trying to pull GET/POST parameters. If you want to do this, you should append the key/values onto the URL ( url: http://localhost:51870/code/Login.aspx?Name=XXXX&Password=YYYYY ) or pass the data using this format ( data: Name=XXXX&Password=YYYYY ).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.