私はAngular JSアプリケーションにWcf Serviceを使用しています。私はユーザー名とパスワードを提供してユーザーログインシステムを作成しています。しかし、これまでに入力したユーザー名やパスワードは、常にユーザー名とパスワードを表示するメッセージが正しいものです。ユーザー名とパスワードが正しい場合は、角度jsアプリケーションにメッセージを表示する必要があります。そうでなければ、ユーザー名とパスワードは正しくありませんが、アプリケーションを実行すると同じメッセージが表示される理由はわかりません。Angular JS Application Script.JSがエラーメッセージを返すように提出しました
ここは私ですスクリプトコード。
///// <reference path="../angular.min.js" />
var app = angular.module("WebClientModule", [])
.controller('Web_Client_Controller', ["$scope", 'myService', function ($scope, myService) {
$scope.OperType = 1;
//1 Mean New Entry
//To Clear all input controls.
function ClearModels() {
$scope.OperType = 1;
$scope.Username = "";
$scope.Password = "";
}
$scope.login = function() {
var User = {
Username: $scope.Username,
Password: $scope.Password,
};
myService.AuthenticateUser(User).then(function (pl) {
$scope.msg = "Username and password is correct ";//Always hit on this line
}, function (err) {
$scope.msg = "Password Incorrect !";
console.log("Some error Occured" + err);
});
};
}]);
app.service("myService", function ($http) {
// Create new record
this.AuthenticateUser = function (User) {
return $http.post("http://localhost:52098/HalifaxIISService.svc/AuthenticateUser", JSON.stringify(User));
}
})
ここに私のHTMLコードが..です(あなたが述べたように)ここでは、あなたのAJAXの応答は 'true' または 'false' テキストであると仮定すると、
@{
Layout = null;
}
<!DOCTYPE html>
<html ng-app="WebClientModule">
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<script src="~/Scripts/angular.min.js"></script>
<script src="~/RegistrationScript/LoginScript.js"></script>
</head>
<body>
<table id="tblContainer" data-ng-controller="Web_Client_Controller">
<tr>
<td></td>
</tr>
<tr>
<td>
<div style="color: red;">{{msg}}</div>
<table style="border: solid 4px Red; padding: 2px;">
<tr>
<td></td>
<td>
<span>Username</span>
</td>
<td>
<input type="text" id="username" data-ng-model="Username" required="" />
</td>
</tr>
<tr>
<td></td>
<td>
<span>Password</span>
</td>
<td>
<input type="password" id="password" required data-ng-model="Password" require="" />
</td>
</tr>
<tr>
<td></td>
<td></td>
<td>
<input type="button" id="Login" value="Login" data-ng-click="login()" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
<script src="~/RegistrationScript/LoginScript.js"></script>
ログインが間違っていると、サービスからエラーコードが送信されますか?それはあなたに別の成功コード、または別のmsgを送信している可能性があります...しかし、依頼はまだ成功しているので、msgは常に成功したものです。ブラウザのDev ToolsのNetworkingタブで応答を観察します。 – dev8080
wcfサービスではブール値のメソッドであり、trueまたはfalseのみを返します。間違ったユーザー名またはパスワードを入力するとfalseが返されますが、Angular jsアプリケーションでは常にユーザー名とパスワードが正しく表示されます。その絶対にヒットした関数のエラーメソッド – Mohammad
pl.dataで返されるものを使用してください – dev8080