【发布时间】:2017-10-10 21:42:34
【问题描述】:
我在使用JSON 服务器登录表单时遇到问题。我有像Username and password 这样的登录凭据并试图执行它。我在服务器上使用了POST,指定了用户插入的用户名和密码。服务器应在指定条件上执行查询,以检查是否有任何具有该名称和密码的行。如果是则返回真,如果是假则返回假。那么客户端应该解析这个响应。
这是我的 HTML 代码:
<form ng-submit="loginform(logcred)" name="logform"><br/><br>
<tr ng-repeat="logcred in loginfo"></tr>
<div>
<label form="emailinput"><b>Email</b></label>
<input type="email" class="form-control" name="uname" id="emailinput" placeholder="you@example.com" ng-model="logcred.username" >
</div>
<div>
<label form="pwdinput"><b>Password</b></label>
<input type="password" class="form-control" name="pwd" id="pwdinput" placeholder="*******" ng-model="logcred.password">
</div>
<div>
<button type="cancel" class="btn" ng-click="toggle_cancel()">Cancel</button>
<button class="btn btn-primary" ng-click="submit()">Login</button>
</div>
</form>
这是使用 AngularJS 的 Javascript 代码:
var myApp = angular.module('myApp', []);
myApp.controller('credientials', function($scope, $http) {
$http.get('http://localhost:3000/loginfo')
.then(
function successCallback(response){
$scope.loginfo == response.data;
$scope.loginform = function(loginfo,username,password){
console.log(loginfo);
$http({
url :'http://localhost:3000/loginfo',
method : 'POST',
data : loginfo
})
.then(
function successCallback(response){
$scope.loginfo = response.data;
if (username === username && password === password) {
console.log(response);
}
else
{
console.log("Error: " + response)
}
});
}
});
我正在从我的服务器正确获得响应。但是当我使用POST 使用if 条件匹配数据时,我不明白我在做什么错误?
任何帮助/建议将不胜感激。
【问题讨论】:
-
你在
response.data得到了什么? -
在
get方法中,我从我的服务器获取用户名和密码。在post中,我从用户那里获取输入的用户名和密码
标签: javascript angularjs json