AngularJS用户登录到Json文件 [英] AngularJS User Login to Json file
问题描述
我当前正在尝试创建一个用户登录页面,其中用户信息存储在 json 文件中.我已经在文件中创建了 GET 方法,但是在用户成功登录后,似乎无法重定向.你能帮我吗?
I am currently trying to create a user login page where the user information is stored on a json file. I have created my GET method to the file but I cannot seem to redirect after the user has logged in successfully. Can you help me out?
我知道在客户端完成的用户登录和验证是一个错误的想法,但这就是我想要在不使用数据库的情况下进行的操作.
I know that user login and validation done on the client side is A BAD IDEA but that is how I want to do it, without using a database.
这是我的HTML代码:
Here is my HTML code:
<body ng-controller="myCtrl">
<form id="login-form">
<h3>User Login</h3>
<div class="form-group">
<label for="email">Email address:</label>
<input type="email" class="form-control" id="email">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd">
</div>
<button type="submit" class="btn btn-default" id="login-button" ng-click="LogOn()">Login</button>
</form>
</body>
我的JavaScript代码:
My JavaScript code:
var app = angular.module('myApp', [ ]);
app.controller("myCtrl",['$scope', '$http', function($scope, $http){
$scope.LogOn = function(){
$http.get('data.json').then(function(data){
$scope.users = data;
});
if (data.email == email) && (data.password = password{
window.location.href = 'www.google.com';
}
};
}]);
我的JSON文件:
[
{
"email":"something@yahoo.com",
"Password":"password"
},
{
"email":"test@yahoo.com",
"password":"test999"
},
{
"email":"xxx@mail.xx",
"password":"xxx"
}
]
推荐答案
请尝试打开链接并检查并运行在w3学校中部署的代码 https://www.w3schools.com/code/tryit.asp?filename= FDVZY3NXVYG6
Please try to open the link and check and run the code which is deployed in w3 schools https://www.w3schools.com/code/tryit.asp?filename=FDVZY3NXVYG6
这篇关于AngularJS用户登录到Json文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!