Bootstrap+angulerjs实现异步登陆

管理员 发布于 5年前   383

html:

<body style="background:#fff;" ng-app="Ajax" ng-controller="Ajax">
<form>
	<div class="form-group" style="margin-bottom: 5px;">
		 <label for="inputEmail3" class="col-sm-2 control-label">Email</label>
		<div class="col-sm-10">
			<input type="email" ng-model="email" class="form-control" id="inputEmail3" />
			<span id="check_user" style="font-size: 8px;color: red;display: none;"></span>
		</div>
	</div>
	<div class="form-group" style="margin-bottom: 0px;">
		 <label for="inputPassword3" class="col-sm-2 control-label">Pass</label>
		<div class="col-sm-10">
			<input type="password" ng-model="password" class="form-control" id="inputPassword3" />
		</div>
	</div>
	<div class="form-group">
		<div class="col-sm-offset-2 col-sm-10">
			<div class="checkbox">
				 <label><input type="checkbox" />Remember me</label>
			</div>
		</div>
	</div>
	<div class="form-group">
		<div class="col-sm-offset-2 col-sm-10">
			 <button type="submit" ng-click="get_more();" class="btn btn-primary btn-large">Sign in</button>
		</div>
	</div>
</form>
js:
<script type="text/javascript"> 
    var myModule = angular.module("Ajax",[]);
    myModule.controller("Ajax",["$scope","$http",function Ajax($scope,$http){
      $scope.get_more = function(){
        $http({
            method: "POST",
            url: "login",
            data:{'username':$scope.username,
               'email':$scope.email,
               'password':$scope.password
              }
          }).
          success(function(data, status) {
           //$scope.status = status;
            $scope.users = data;
	        if (data.error == 1) {
	            alert(data.info);
	            location.reload();
	        }else{
	           $("#check_user").html(data.info);
	            $("#check_user").css("display","block");
	        };
            
          }).
          error(function(data, status) {
           //$scope.data = data || "Request failed";
           //$scope.status = status;
         });
       }
    }]);
</script> 

效果:(用file_get_contents("php://input")获取参数,在json_decode转)
{ email: "11", password: "1"}


请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!

该博客于2020-12-7日,后端基于go语言的beego框架开发
前端页面使用Bootstrap可视化布局系统自动生成

是我仿的原来我的TP5框架写的博客,比较粗糙,底下是入口
侯体宗的博客

      订阅博客周刊

文章标签

友情链接

HouTiZong
侯体宗的博客
© 2020 zongscan.com
版权所有ICP证 : 粤ICP备20027696号
PHP交流群
侯体宗的博客