How to authenticate username password in Jquery with asp.net?

后端 未结 2 894
伪装坚强ぢ
伪装坚强ぢ 2021-01-17 07:01

I have code of Jquery login control loke following using this into asp.net but but confused where and how I can simply authenticate username and password.

Logi

2条回答
  •  无人及你
    2021-01-17 07:45

    Here's how you can write an ajax call to start with

    var usernameText = $("#usernameTextbox");
    var passwordText = $("#passwordTextbox");
    
    $.ajax({
        type: 'GET',
        url: '/Account/ValidateUser',
        async: true,
        dataType: 'json',
        data:
        {
            userName: usernameText,
            password: passwordText
        },
        success: function(result) {
            if(result){
                // redirect user to required page
            }
            else{
                // show error on some div that usrname and password do not match
            }
        }
    });
    

    Related Question on SO

    MVC 4 Jquery Ajax call returns login page html

    How to use Basic Auth with jQuery and AJAX?

提交回复
热议问题