Login Page using ASP.Net & Ajax

Posted by user1293474 on Stack Overflow See other posts from Stack Overflow or by user1293474
Published on 2012-04-03T17:26:36Z Indexed on 2012/04/03 17:29 UTC
Read the original article Hit count: 293

Filed under:
|
|
|
|

I'm trying to make a login page using html, ajax & ASP.NET.The data is truly passed to the ajax function, but when I debug the asp page the username and password are sent with NULL. The code is supposed to take username & password then returns the userid

Html page:

    <div id="usernameid">Username:</div><input id="username" type="text"/> <span id="username_status"></span>
    <div id="passwordid">Password:</div><input id="password" type="password"/> <span id="password_status"></span>
    <div> <input id="loginbutton" onclick="UserLogin()" type="submit" value="Submit" /></div>

Javascript:

function UserLogin() {
var postData = JSON.stringify({ "username": JSON.stringify($("#username").val()), "password": JSON.stringify($("#password").val()) });
alert(postData);
$.ajax({
    type: "GET",

    url: "http://localhost:49317/LoginPageForLearn.aspx",
    data: postData,
    contentType: "application/json; charset=utf-8",
    dataType: "jsonp",
    jsonp: 'jsoncallback',
    success: callbackfunction,
    error: function (msg) { alert(msg); }
    }); 
    }

Asp.net page:

protected void Page_Load(object sender, EventArgs e)
    {

        string userName = "";
        int userId = -1;
        string PassWord = "";
        if (Request.QueryString.Count != 0 && Request.QueryString["username"] != string.Empty && Request.QueryString["password"] != string.Empty)
            {
                userName = Request.QueryString["username"];
                PassWord = Request.QueryString["password"];
                userId = GetUserID(userName, PassWord);

            }
    }

Do you have any ideas why isn't the data passed correctly ? Or do you have any other ideas on how can I make a login page using html and access the data at SQL.

Thanks a lot.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about ASP.NET