Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.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 json文件未加载到浏览器_Javascript_Json_Angularjs_Firefox - Fatal编程技术网

Javascript json文件未加载到浏览器

Javascript json文件未加载到浏览器,javascript,json,angularjs,firefox,Javascript,Json,Angularjs,Firefox,我是angularjs的新手,我正在做角度控制器和模型的简单研究。 这是我的javascript模型代码 var testApp = angular.module('testApp', []); testApp.controller('testCtrl', function testCtrl($scope ,$http) { $http.get('test.json').success(function ($data){ $scope.artists = $data;

我是angularjs的新手,我正在做角度控制器和模型的简单研究。 这是我的javascript模型代码

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

testApp.controller('testCtrl', function testCtrl($scope ,$http) {

  $http.get('test.json').success(function ($data){

   $scope.artists = $data;

  });

});
网页已加载,但出现异常。我在Windows7中使用firefox

[异常…”“拒绝访问受限URI”代码:“1012”nsresult:“0x805303f4>>(NS\u错误\u DOM\u错误\u URI)”位置:file:///....// angular.min.js线条:72“]

有人知道解决办法吗。。
我不需要在服务器上运行它,只需要使用本地机器。

您必须对角度控制器语法做一个小的修改

testApp = angular.module('testApp', []);
testApp.controller('testCtrl', function($scope, $http) {
    $http.get('test.json').success(function($data) {
       $scope.artists = $data;
    });
});

正如上面的评论中已经提到的,这可能是因为Firefox的安全性阻止了您的代码访问本地文件系统中的文件

您可以通过更改浏览器的配置来配置Firefox以访问本地内容

在Firefox中:

  • 转到about:config
  • 查找security.fileuri.strict\u origin\u策略参数
  • 将其设置为false

在chrome中禁用web安全性检查一次,如果出现相同的错误,则json文件的url中可能存在问题

通过


您可能会发现问题所在。

您需要将json文件托管在服务器中。由于安全原因,从文件中加载它受到限制。我认为fire fox的安全性导致了这一点。我认为你是一名学生,你在当地做这件事的目的是什么。检查另一个浏览器。多纳尔谢谢,但我如何修复它。奇兰:这只是为了教育,但如果它可以修复,那就好了。定义控制器时,不要在函数旁边给出控制器名称。所以我把它去掉了。所以,这不是问题的答案。顺便说一句,控制器名称在调试时可能很有用。事实上,我认为问题不在于代码。我想这是因为浏览器效应。。但是无论如何谢谢你。。