0

次のコードを使用して angular.js の json ファイルにアクセスしたいのですが、以下に示すエラーのためにコードにアクセスできません。助けていただければ幸いです。

モジュール:

angular.module("demoApp", ['demoApp.factory','demoApp.controllers']);

工場:

angular.module('demoApp.factory', []).
factory('getJsonDataFactory',function($http){
    return{
    getData : function() {
        return $http.get('mapData.json');
    }
 }
});

コントローラー:

angular.module('demoApp.controllers', []).
  controller('GetJsonController', function($scope,$http,getJsonDataFactory) {
              $scope.markers = [];  
              getJsonDataFactory.getData().success(function(data){
                $scope.photos=data;
            });
        });

エラー: Firefox の場合:

 "Access to restricted URI denied" code: "1012"


return logFn.apply(console, args)

Chrome で :`

Origin null is not allowed by Access-Control-Allow-Origin.
4

1 に答える 1

7

実際、あなたはサーバーを持っていないと思います。

したがって、file://プロトコルを介してアプリケーションを取得しています。

ただし、セキュリティ上の理由から、file://プロトコルは http get メソッドを実行できません

あなたの問題を解決するには、アプリケーションを単純なWebサーバー(Apache、またはwamp、xamp、lampなど)に配置するか、gruntを使用してアプリケーションを構築し、node.jsを介してテストサーバーで実行することをお勧めします

于 2013-10-01T13:08:05.797 に答える