Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/367.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 “;拒绝访问受限URI”;或找不到文件路由_Javascript_Jquery_Angularjs_Url Routing_Angularjs Routing - Fatal编程技术网

Javascript “;拒绝访问受限URI”;或找不到文件路由

Javascript “;拒绝访问受限URI”;或找不到文件路由,javascript,jquery,angularjs,url-routing,angularjs-routing,Javascript,Jquery,Angularjs,Url Routing,Angularjs Routing,我正在尝试在Angular中配置路由。以下是我所拥有的: <!DOCTYPE html> <html ng-app="countryApp"> <head> <meta charset="utf-8"> <title>Angular.js-add routes</title> <script src="http://cdnjs.cloudflare.com/ajax/libs/angular.j

我正在尝试在Angular中配置路由。以下是我所拥有的:

<!DOCTYPE html>
<html ng-app="countryApp">
<head>
    <meta charset="utf-8">
    <title>Angular.js-add routes</title>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.3/angular.js"></script>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.3/angular-route.min.js"></script>
    <script>

        var countryApp = angular.module('countryApp', ['ngRoute']);

        countryApp.config(function($routeProvider){
            $routeProvider.
                when('/',{
                    template: '<ul><li ng-repeat="country in countries">{{country.countryName}}</li></ul>',
                    controller: 'CountryListCtrl'
                    }).
                when('/:countryName',{
                    template: '<h1>TODO create country detail view</h1>',
                    controller: 'CountryDetailCtrl'
                    }).
                otherwise({
                    redirectTo:'/'
                    });
        });

        countryApp.controller('countryListCtrl', function($scope,$http){
            $http.get('countries.php').success(function(data){
                $scope.countries=data;
            });
        });
        countryApp.controller('countryDetailCtrl', function($scope,$routeParams){
            console.log($routeParams);
            });


    </script>
</head>
<body ng-controller= "countryListCtrl"> 

<ul>
    <li ng-repeat="country in countries">{{country.countryName}}</li>
</ul>
</body>
</html>

Angular.js-add路由
var countryApp=angular.module('countryApp',['ngRoute']);
countryApp.config(函数($routeProvider){
$routeProvider。
当(“/”{
模板:“
  • {{country.countryName}
”, 控制器:“CountryListCtrl” }). 当(“/:countryName”{ 模板:“TODO创建国家/地区详细信息视图”, 控制器:“CountryDetailCtrl” }). 否则({ 重定向到:'/' }); }); countryApp.controller('countryListCtrl',函数($scope,$http){ $http.get('countries.php').success(函数(数据){ $scope.countries=数据; }); }); countryApp.controller('countryDetailCtrl',函数($scope,$routeParams){ 控制台日志($routeParams); });
  • {{country.countryName}
上述代码保存在ng-app.html文件中。

我的问题:
ng-app.html-works
ng-app.html/-不起作用。给予对受限URI的访问被拒绝…“错误
ng-app.html/USA-不起作用。给出“找不到文件”错误页

当我尝试在服务器(localhost)上运行上述文件时,对于上述两种“不工作”情况,我都会得到一个“找不到文件”错误页面。

谢谢@charlietfl。 最终的url确实是:ng app.html#/USA

我还想指出,我犯了一些错误。控制器countryListCtrl和countryDetailCtrl在定义中都以小写字母c开头。但是我在路由部分使用了大写的C。

应该是
ng app.html#/USA
基于您的配置,因为您没有设置
HTML5模式