Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 应用程序在Internet Explorer中重定向到主页(角度路由)_Javascript_Angularjs_Cookies_Angular Routing - Fatal编程技术网

Javascript 应用程序在Internet Explorer中重定向到主页(角度路由)

Javascript 应用程序在Internet Explorer中重定向到主页(角度路由),javascript,angularjs,cookies,angular-routing,Javascript,Angularjs,Cookies,Angular Routing,我正在使用angularJs将任何用户在接受条款和条件后重定向到request.html,单击termsandconditions.html上的复选框。$cookies功能适用于除IE之外的所有其他浏览器。对于IE来说,这种行为很奇怪 第一次,portalApp.run函数中的警报显示“是”,但第二次之后,我看到第二个警报显示“未定义”,因为控件转到了else,页面被重定向到“/” 我在第二个警报中看到undefined的原因可能是在IE中再次调用了“/”url,但这次没有调用saveData函

我正在使用angularJs将任何用户在接受条款和条件后重定向到request.html,单击termsandconditions.html上的复选框。$cookies功能适用于除IE之外的所有其他浏览器。对于IE来说,这种行为很奇怪

第一次,portalApp.run函数中的警报显示“是”,但第二次之后,我看到第二个警报显示“未定义”,因为控件转到了else,页面被重定向到“/”

我在第二个警报中看到undefined的原因可能是在IE中再次调用了“/”url,但这次没有调用saveData函数。然而,我不明白为什么IE中会有第二个调用“/”而不是其他浏览器

requestForm.jsp


嗨,谁能帮我指出这里出了什么问题您是否已检查IE中是否启用了Cookie?你正在使用哪个版本的IE?您是否尝试过使用localStorage/sessionStorage?如果可能未启用Cookie,您应该依靠服务来存储数据。感谢您的回复-@EliteOctagon。我试过使用sessionStorage和localStorage,它们工作正常。我在IE中看到两次“是”,但在其他浏览器中只看到一次。$cookies的问题是,它在第二个警报中给出了未定义的消息。我想知道为什么IE会导致双程呼叫,因此在第一时间会出现两次警报。回复你的Qs-I。是,已启用Cookie。我确实看到第一警报ii的“是”。IE8,但我也在IE9上复制了这一点。它是否与IE中提交按钮上的两个调用有关?
<form name="formName" style="margin-top:10px;" method = "post">
<input type="submit" ng-model="butn" ng-click="saveData()">
</form>
var portalApp=angular.module('portalApp',['ngRoute','ngCookies','ngSanitize']);
 portalApp.config(function($routeProvider) {

            $routeProvider

            .when('/', {
                templateUrl: '/termsandconditions.html',
                controller: 'ackController'
            })
            .when('/request', {
                templateUrl: '/request.html',
                controller: 'reqController'
            })
            .otherwise({
                redirectTo: '/'
            });
        });

portalApp.run(function($rootScope, $location, $cookies) {
        $rootScope.$on('$locationChangeStart', function(ev, next, current) {

            //checking url on location change start
            if($location.path().indexOf('/request') == '0'){
                var msg = $cookies.hasReadTerms;
                alert(msg); // Alert to show cookie content

                //checking cookies while accesing unlock request page
                if(msg == 'yes'){
                    //user can access request page
                } else {
                    //redirecting user to entry page
                    $location.path('/');
                }
            }
        });
    });


portalApp.controller('ackController', function($scope,$rootScope,$location,$cookies){ 

        $scope.saveData = function(){

            //setting cookies for user acknowledgement
            $cookies.hasReadTerms = 'yes';
            $location.path('/request');
        }
    });


portalApp.controller('reqController', function($scope,$rootScope,$location,$cookies){
// do something
}