62,074
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>系统登录</title>
<link href="styles/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link href="styles/style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
body { margin-top:50px; }
</style>
</head>
<body>
<div ng-app="loginApp">
<div class="container" ng-controller="loginController">
<div class="form-horizontal login-box">
<div class="form-group">
<div class="col-sm-2"><label class="control-label" for="txtUsername">用户名</label></div>
<div class="col-sm-10">
<input type="text" id="txtUsername" class="form-control" placeholder="用户名" ng-model="data.username">
</div>
</div>
<div class="form-group">
<div class="col-sm-2"><label class="control-label" for="txtUsername">密码</label></div>
<div class="col-sm-10">
<input type="password" id="txtPassword" class="form-control" placeholder="密码" ng-model="data.password">
</div>
</div>
<div class="form-group">
<div class="col-sm-12 text-right">
<button type="button" class="btn btn-primary" ng-click="login()">登录</button>
</div>
</div>
</div>
</div>
</div>
<script src="scripts/angular.min.js" type="text/javascript"></script>
<script src="scripts/login.js" type="text/javascript"></script>
</body>
</html>
var app = angular.module("loginApp", [])
.controller("loginController", ["$scope", "$http", function ($scope, $http) {
$scope.login = function () {
$scope.data = {};
console.log($scope.data.username,$scope.data.password);
// if($scope.data.username == undefined || $scope.data.password == undefined){
// alert("用户名和密码不能为空!");
// return false;
// }
$http({
method : "POST",
url : "../handlers/LoginHandler.ashx",
params : { username : $scope.data.username , password : $scope.data.password }
}).then(function successCallback(response){
if(response.data == 0){
alert("用户名或密码错误!");
}else{
location.href = "index.aspx";
}
},function errorCallback(){
});
}
} ]);
var app = angular.module("loginApp", [])
.controller("loginController", ["$scope", "$http", function ($scope, $http) {
$scope.data = {};
$scope.login = function () {
console.log($scope.data.username,$scope.data.password);
// if($scope.data.username == undefined || $scope.data.password == undefined){
// alert("用户名和密码不能为空!");
// return false;
// }
$http({
method : "POST",
url : "../handlers/LoginHandler.ashx",
params : { username : $scope.data.username , password : $scope.data.password }
}).then(function successCallback(response){
if(response.data == 0){
alert("用户名或密码错误!");
}else{
location.href = "index.aspx";
}
},function errorCallback(){
});
}
} ]);
另外,验证的话用Angular来验证,参考
http://www.runoob.com/angularjs/angularjs-validation.html
http://www.cnblogs.com/rohelm/p/4033513.html