获取RangeError:使用angular.js和php

时间:2015-10-05 09:30:27

标签: javascript php angularjs

使用angular.js路由页面时出现以下错误。

  

错误:

RangeError: Maximum call stack size exceeded
    at $ (http://oditek.in/Gofast/js/angularjs.js:73:115)
    at K (http://oditek.in/Gofast/js/angularjs.js:62:39)
    at h (http://oditek.in/Gofast/js/angularjs.js:54:410)
    at http://oditek.in/Gofast/js/angularjs.js:53:480
    at http://oditek.in/Gofast/js/angularjs.js:55:397
    at r (http://oditek.in/Gofast/js/angularjs.js:60:200)
    at x (http://oditek.in/Gofast/js/angularroute.js:6:364)
    at link (http://oditek.in/Gofast/js/angularroute.js:7:92)
    at $ (http://oditek.in/Gofast/js/angularjs.js:73:89)
    at K (http://oditek.in/Gofast/js/angularjs.js:62:39) <!-- ngView:  -->

我正在解释下面的代码。

  

的index.html:

<!DOCTYPE html>
<html lang="en" ng-app="Channabasavashwara">
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>...:::WELCOME TO Channabasavashwara Institude of Technology:::...</title>

    <!-- PACE LOAD BAR PLUGIN - This creates the subtle load bar effect at the top of the page. -->
    <link href="css/pace.css" rel="stylesheet">
    <script src="js/pace.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="js/angularjs.js" type="text/javascript"></script>
    <script src="js/angularroute.js" type="text/javascript"></script>
    <script src="controller/loginRoute.js" type="text/javascript"></script>
    <!-- GLOBAL STYLES - Include these on every page. -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href='http://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700,300italic,400italic,500italic,700italic' rel="stylesheet" type="text/css">
    <link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel="stylesheet" type="text/css">
    <link href="icons/font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <link rel="shortcut icon" href="img/favicon.png">
    <!-- PAGE LEVEL PLUGIN STYLES -->
    <!-- THEME STYLES - Include these on every page. -->
    <link href="css/style.css" rel="stylesheet">
    <link href="css/plugins.css" rel="stylesheet">
    <link href="css/chosen.css" rel="stylesheet">

    <!-- THEME DEMO STYLES - Use these styles for reference if needed. Otherwise they can be deleted. -->
    <link href="css/demo.css" rel="stylesheet">
    <!-- PAGE LEVEL PLUGIN STYLES -->
    <!-- THEME STYLES - Include these on every page. -->
    <link href="css/load.css" rel="stylesheet">
    <script src="js/jquery.min.js"></script>
    <!-- THEME DEMO STYLES - Use these styles for reference if needed. Otherwise they can be deleted. -->
    <!--[if lt IE 9]>
      <script src="js/html5shiv.js"></script>
      <script src="js/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div ng-view>
</div>
    <!-- GLOBAL SCRIPTS -->
    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/jquery.slimscroll.min.js"></script>
    <script src="js/jquery.popupoverlay.js"></script>
    <script src="js/defaults.js"></script>
    <!-- Logout Notification Box -->

    <!-- /#logout -->
    <!-- Logout Notification jQuery -->
    <script src="js/logout.js"></script>
    <!-- HISRC Retina Images -->

    <!-- THEME SCRIPTS -->
    <script src="js/flex.js"></script>
    <script src="js/dashboard-demo.js"></script>
    <script src="js/chosen.jquery.js" type="text/javascript"></script>
    <script src="js/prism.js" type="text/javascript"></script>
    <script src="js/shortcut.js"></script>
    <!-- HISRC Retina Images -->

    <!-- THEME SCRIPTS -->
    <link rel="stylesheet" type="text/css" href="calendar/tcal.css" />
    <script type="text/javascript" src="calendar/tcal.js"></script> 
    <script src="js/newbill.js"></script>
    <script src="controller/loginController.js" type="text/javascript"></script>
    <script src="controller/dashboardController.js" type="text/javascript"></script>
</body>
</html>

这里我首先要登录一个登录页面。当用户成功登录时,应该显示仪表板页面,但是它会抛出上述错误。

  

loginRoute.js:

var Admin=angular.module('Channabasavashwara',['ngRoute']);
Admin.config(function($routeProvider){
    $routeProvider
    .when('/',{
        templateUrl: 'dashboardview/login.html',
        controller: 'loginController'
    })
    .when('/dashboard',{
        templateUrl: 'dashboardview/dashboard.html',
        controller: 'dashboardController'
    });
})
  

loginController.js:

var loginAdmin=angular.module('Channabasavashwara');
loginAdmin.controller('loginController',function($scope,$http){
    $scope.user_name = ''; 
    $scope.user_pass = '';
    $scope.user_login=function(){
    if($scope.user_name==''){
        alert('user name filed should not keep blank');
    }else if($scope.user_pass==''){
        alert('password filed should not keep blank');
    }else{
        var userData={'user_name':$scope.user_name,'user_pass':$scope.user_pass};
        console.log('user',userData);
        $http({
            method: 'POST',
            url: "php/Login/login.php",
            data: userData,
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
        }).then(function successCallback(response){
            console.log('response',response);
            alert(response.data['msg']);
            location.href='#dashboard';
        },function errorCallback(response) {
            alert(response.data['msg']);
        });
    }
    }
});

这里我首先获得登录页面。完成成功登录后,它应该重定向到仪表板页面,但是这个错误即将到来。请帮我解决这个错误。

1 个答案:

答案 0 :(得分:1)

在控制器中添加$locationloginAdmin.controller('loginController',function($scope,$http, $location){

并将location.href='#dashboard';替换为 $location.path('/dashboard');