从Angular中的json文件读取数据时出错

时间:2017-07-26 19:28:50

标签: angularjs json

请不要downvote。我正在努力寻找解决方案。同一段代码正在另一台机器上运行。有人可以帮我解决这个问题吗?

代码:

mainApp.controller('mainCtrl', function($scope,$http){
    $http.get('./data.json')
    .success(function(response){
        $scope.record = response.data;

错误:

XMLHttpRequest cannot load file:///C:/Users/reddy/Angular/data.json. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

非常感谢任何形式的帮助。

1 个答案:

答案 0 :(得分:0)

如果您只是想在Chrome中工作时消除此问题,可以像这样添加Chrome扩展程序:

https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?hl=en

相关问题