javascript - json 文件未加载到浏览器

标签 javascript json angularjs firefox

我是 angularjs 的新手,我正在对 Angular Controller 和模型进行简单的研究。 这是我的 javascript 模型代码。

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

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

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

   $scope.artists = $data;

  });

});

网页已加载但出现异常。我在 Windows 7 中使用 firefox。

[Exception... "Access to restricted URI denied" code: "1012" nsresult: "0x805303f4 >.>(NS_ERROR_DOM_BAD_URI)" location: "file:///....// angular.min.js Line: 72"]

有人知道解决办法吗... 我不需要在服务器中制作它只需要使用本地机器..

最佳答案

您必须对 Angular Controller 语法做一个小的修正。

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

关于javascript - json 文件未加载到浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25360674/

相关文章:

javascript - XMLHttpRequest undefined,angular mock-ajax 源码不监听ajax调用?

javascript - Angular 2 - 合并(扩展)对象

angularjs - 如何使用 Jasmine、AngularJs 测试 _.defer()

javascript - 解析 JSON 返回值

仅限 javascript - 如何过滤特定的 div 类?

Python使用json读取一个带表情的字符串

angularjs - 将数组传递给 angularJs 中的 $location.search

angularjs - 如何从 $routeProvider 中删除路由

javascript - 将 JSON 数组的一部分与另一个 JSON 数组组合起来

javascript - 用从 php 文件返回的 json 值替换固定的 json 变量