使用angularjs在主题上重定向URL问题

时间:2015-03-25 06:47:25

标签: php angularjs cookies

我在使用angular js重定向到主题上的特定网址时遇到问题。 基本上,在主题上,我有一个login.html文件,然后在验证用户是否在数据库中之后应该重定向到dashboard.html。如果没有,它将保留在登录页面上。

我实现此功能没有问题。但是,我正在尝试实现类似会话的功能,它在传输到仪表板时保留登录页面中的变量。目前,我正试图通过ajax调用将变量存储在php $ _SESSION中来实现。

登录页面是:

<!doctype html>
<!-- <html ng-app='login'> -->
<html ng-app="dashboardApp" ng-controller="MainCtrl" class="no-js {{containerClass}}">
<head>
<link rel="stylesheet" href="styles/vendor.00b812ba.css">
<link rel="stylesheet" href="styles/main.02bb4eb8.css">

</head>
<body ng-controller='loginBodyCtrl'>
<form id = 'redirectToDashboard' ng-submit = 'newDataSource()'>
<label>Username</label>
<input id = 'name' type = 'text' ng-model='formData.name'></input>
<label>Password</label>
<input id = 'password' type = 'password' ng-model='formData.password'></input>
<!-- <input type = 'Submit'> -->
<input type = 'Submit'>
</form>

<form id = 'forgotPassword'>
<label>Forgot your password? Click here!</label>
<input type = 'Submit'>
</form>
</body>
</html>

<script src="scripts/vendor.297ae76c.js"></script> <!-- Script which contains angularjs -->
<script src="scripts/old_app.11997041.js"></script> <!-- Declares cookies -->
<!-- Custom Script for OLD -->
<script src="scripts/old_custom_script.js"></script>

登录页面的控制器是这个(old_custom_script.js):

'use strict';

angular.module('dashboardApp')
.controller('loginBodyCtrl', function ($scope, $http) 
// .controller('loginBodyCtrl', ['$cookies', function ($scope, $http, $cookies) 
{

$scope.formData = {name: 'John Smith', password: 'Password'};

$scope.newDataSource = function()
{
$http({
method  : 'POST',
url     : './ajax/checkLoginCreds.php',
data    : $.param($scope.formData),  // pass in data as strings
headers : { 'Content-Type': 'application/x-www-form-urlencoded' }  // set the headers so angular passing info as form data (not request payload)
})
.success(function(data) 
{
console.log(data);
if(data == 0)
{
// $cookies.put('authCookie', 'declined');
console.log('Credentials incorrect.');
}
else if(data == 1)
{
/** if username and password is correct - goes to dashboard **/
// $cookies.put('authCookie', 'approved');
window.location.replace("./dashboard.html");
}
else
{
console.log('Dashboard is currently unavailable.'); 
}
});
};
});

包含仪表板控制器的文件old_app.js特别包含此代码段,这会导致我出现问题:

angular.module('dashboardApp')
.controller('MainCtrl', function ($scope, $http, $location) {

$scope.main = {
title: 'Minovate',
settings: {
navbarHeaderColor: 'scheme-default',
sidebarColor: 'scheme-default',
brandingColor: 'scheme-default',
activeColor: 'default-scheme-color',
headerFixed: true,
asideFixed: true,
rightbarShow: false
}
};

$scope.ajaxFaker = function(){
$scope.data=[];
var url = 'http://www.filltext.com/?rows=10&fname={firstName}&lname={lastName}&delay=5&callback=JSON_CALLBACK';

$http.jsonp(url).success(function(data){
$scope.data=data;
console.log('cecky');
angular.element('.tile.refreshing').removeClass('refreshing');
});
};

$http({
method  : 'GET',
url     : './ajax/checkAuthentication.php',
headers : { 'Content-Type': 'application/x-www-form-urlencoded' }  
// set the headers so angular passing info as form data (not request payload)
})
.success(function(data) 
{
console.log(data);
if(data == 0)
{
// $cookies.put('authCookie', 'declined');
// console.log('Credentials incorrect.');
window.location.replace("./login.html");
}
else if(data == 1)
{
/** if username and password is correct - goes to dashboard **/
// $cookies.put('authCookie', 'approved');
console.log('Dashboard successfully accessed.'); 
}
else
{
window.location.replace("./login.html");
}
});
});

请注意

 window.location.replace("./login.html") 

每次执行此操作时,网址都会重定向到

url.../login.html/#/dashboard/app 

但浏览器 CRASHES

我不知道是什么导致了这个问题,因为old_custom_script.js中的类似行正在完美地运行。有人可以帮忙吗?

0 个答案:

没有答案