2016-01-10 211 views
0

我想從http://localhost:8080/daddy/訪問JSON。本頁面由後臺的glassfish服務器提供支持。我能夠從瀏覽器訪問這個網址,我得到以下結果:AngularJS無法訪問本地主機:8080

{"id":11,"content":"Hello, World!"} 

但是,當我嘗試從AngularJS訪問它,我得到以下結果:

{"data":null,"status":0,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"url":"http://localhost:8080/daddy/","headers":{"Accept":"application/json, text/plain, */*"}},"statusText":""} 

***** ** AngularJS腳本********

​​

但是,當我使用任何公共URL獲取JSON,它返回就好。本地主機似乎有問題。任何幫助將不勝感激!

+0

調試器控制檯中是否有任何錯誤消息? – PSWai

+0

它應該不是在你的成功回調中的'response.data'嗎? – TheLazyChap

+0

@TheLazyChap'data'似乎是'null' – PSWai

回答

0

一目瞭然,我沒有看到任何json文件?例如:

$http({ 
    method: 'GET', 
    url: 'http://localhost:8080/daddy/file.json' 
}).then(function successCallback(response) { 
    currentInstance.data = response; 

    }, function errorCallback(response) { 
    currentInstance.data = response ;  
    }); 

你運行本地主機上的應用程序也和你將可以隨着JSON部署它,如果是的話那麼你爲什麼要通過本地主機連接到它?爲什麼不是

$get('../daddy/file.json/').then(function(response)){ 

    }); 

我是相當新的角,但也許這可以幫助你。

相關問題