0
쿠키에 문제가 있습니다. 내 프로젝트에서 ngCookies를 사용할 때 내 div (경고)에 잘못된 것이 있습니다. enter image description here
그리고 여기 내 app.js
angular.module('postLogin', [ngCookies])
.controller('PostController', ['$scope', '$http', function($scope, $http) {
this.postForm = function() {
var encodedString = 'username=' +
encodeURIComponent(this.inputData.username) +
'&password=' +
encodeURIComponent(this.inputData.password);
$http({
method: 'POST',
url: 'userauth.php',
data: encodedString,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
})
.success(function(data) {
//console.log(data);
if (data.trim() === 'correct') {
window.location.href = 'success.html';
} else {
$scope.errorMsg = "Username and password do not match.";
}
})
}
}]);
입니다 그리고 여기에 내가 ngCookies
angular.module('postLogin', [])
그것은 실행할 수를 사용하지 않은 경우 내 index.html을
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="robots" content="noindex"/>
<title>angulrjs login page</title>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"/>
<link href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet" id="main-css"/>
<link href="css/style.css" rel="stylesheet" id="main-css"/>
<script src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<script src="angular.min.js"></script>
</head>
<body ng-app="postLogin" ng-controller="PostController as postCtrl">
<div class="container">
<div id="loginbox" class="mainbox col-md-6 col-md-offset-3 col-sm-6 col-sm-offset-3">
<div class="row">
<img src="images/logo.jpg" class="imglogo"/>
</div>
<div class="panel panel-default" >
<div class="panel-heading">
<div class="panel-title text-center">Login using username & password</div>
</div>
<div class="panel-body" >
<form name="login" ng-submit="postCtrl.postForm()" class="form-horizontal" method="POST">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input type="text" id="inputUsername" class="form-control" required autofocus ng-model="postCtrl.inputData.username"/>
</div>
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
<input type="password" id="inputPassword" class="form-control" required ng-model="postCtrl.inputData.password"/>
</div>
<div class="alert alert-danger" ng-show="errorMsg">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">
×</button>
<span class="glyphicon glyphicon-hand-right"></span> {{errorMsg}}
</div>
<div class="form-group">
<div class="col-sm-12 controls">
<button type="submit" class="btn btn-primary pull-right" ng-disabled="login.$invalid">
<i class="glyphicon glyphicon-log-in"></i> Log in</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<script src="app.js"></script>
</body>
</html>
입니다 정상적으로. 제발 도와주세요. 로그인 양식의 사용자 이름을 다음 페이지로 보내고 싶습니다. 나는 PHP에서 세션과 같은 $ 쿠키를 사용할 수 없습니다. 감사.
죄송합니다. 잘못되었습니다. 나는 모듈 setter [ 'ngCookies']에서 사용할 때 정상적으로 실행할 수 없다는 것을 의미합니다. [ 'ngCookies']를 사용하면 콘솔의 F12 부분 (JS 점)에 체크인했을 때 [$ injector : modulerr]에 오류가있었습니다. 그렇지 않으면 [ 'ngCookies']를 사용하여 콘솔에서 오류가 사라졌습니다 (JS 지점). 제 생각에는 ngCookies에 대해 angular-min.js와 같은 .js 파일이 있어야합니다. 아마도 ? 내가 잘못 ? –
도움을 주셔서 감사합니다. 해결 방법을 알고 있습니다. js (angular-cookies.min.js와 angular.min.js) 부분 만 있으면됩니다. 내 참조는 http://www.tutorialsavvy.com/2014/11/angularjs-cookie-example.html/ 및 http://stackoverflow.com/questions/10961963/how-to-access-cookies-in-angularjs입니다. 이것은 초보자이기 때문에 자바 스크립트를 사용하는 데있어서 처음입니다. 내 바보 같은 질문에 대해 유감입니다. :( –