views:

38

answers:

2

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  A: 

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&amp;Password=YYYYY ) or pass the data using this format ( data: Name=XXXX&Password=YYYYY ).

Zachary
A: 

That's because your ajax is "POST"ing so you should use:

Request.Form["name"];
Request.Form["pwd"];

Ignore my answer and mark it down - I didn't notice the json portion

BuildStarted