javascript - 使用 rest api 和 angularjs 登录 asp.net

标签 javascript jquery html css angularjs

我使用 AngularJS 和 REST API 在 ASP.NET 中创建了一个登录页面, 但我不知道如何创建?

如何使用带有自动生成 token 的 AngularJS 和 REST API 在 ASP.NET 中执行登录操作。

最佳答案

设计表格如下

  <div class="form-box" id="login-box">
        <div class="header">Sign In</div>
        <form>
            <div class="body bg-gray">
                <div class="form-group">
                    <input type="text" name="userid" ng-model="login.user_user" class="form-control" placeholder="User ID"/>
                </div>
                <div class="form-group">
                    <input type="password" name="password" ng-model="login.user_pass" class="form-control" placeholder="Password"/>
                </div>          
                <div class="form-group">
                    <input type="checkbox" name="remember_me"/> Remember me
                </div>
            </div>
            <div class="footer">                                                               
                <button type="submit" class="btn bg-olive btn-block" ng-click="doLogin(login)">Sign me in</button>  


            </div>
        </form>


    </div>

在 Controller 中

//Controller to login
app.controller('login', function ($scope) {
  //initially set those objects to null to avoid undefined error
  $scope.doLogin               = {};
  logdata                      = {};


  $scope.doLogin  = function (logdata) {

                  $http.post('urltopost').then(function(result){
                        if(result.data.flag==1)
                        {
                            window.location = "home.html";
                        }
                        else
                        {
                          alert('Wrong username and password!');
                        }

                  });


  };



}); 

关于javascript - 使用 rest api 和 angularjs 登录 asp.net,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30952133/

相关文章:

javascript - 如何获取以逗号分隔的选定复选框 ID,其值为 1

javascript - 使用带有延迟和操作的 Javascript 创建数组和循环

javascript - 谷歌浏览器拒绝显示 GoogleMaps 框架,因为 X-Frame-Options 设置为拒绝

javascript - 跨浏览器捕获回车键,我的解决方案不起作用

javascript - 使用 jQuery 事件

database - 如何在动态图形/图表上显示数据库数据

php - 前往 PHP 中的另一个页面

jquery - 使用 jQuery 动画旋转单词

javascript - 隐藏的溢出在 iPad 中不起作用

javascript - 动态更改 JQuery Mobile 数据主题