2017-07-26 130 views
0

請不要低估。我試圖找到一個解決方案。同一段代碼在不同的機器上工作。有人可以幫我解決這個問題嗎?從Angular的json文件中讀取數據時出錯

代碼:

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. 

任何形式的幫助是非常讚賞。

+0

COORS問題。當你在服務器上時,'./data.json'的請求會變成類似於'http:// /data.json'的文件,它與剛剛加載到瀏覽器中的頁面位於同一個域中。 'file:/// C:/ Users .../data.json'被認爲是一個不同的域名,chrome將會投訴。 –

+0

file:/// C:/Users/reddy/Angular/index.html是url – Reddy

+0

它在Firefox中工作.. – Reddy

回答