2016-07-06 65 views
0

我試圖發送一個HTTP GET請求來使用此代碼主機:

$scope.completeResult= 
    $resource("api.openweathermap.org/data/2.5/forecast/daily", { callback: "JSON_CALLBACK" }, { get: { method: "JSONP" }}); 

    $scope.finalResult=$scope.completeResult.get({ q: "London", APPID: 'myID' , cnt: 2 }); 
    console.log($scope.finalResult); 

但我得到一個404錯誤。當我檢查了Inspect -> Network事實證明,它發送請求到:http://127.0.0.1:27469/views/api.openweathermap.org/data/2.5/forecast/daily?APPID=myID&callback=angular.callbacks._0&cnt=2&q=London

正如你所看到的,它會發送GET請求,以我的本地,而不是真正的主機

http://127.0.0.1:27469/views/ 

我怎樣才能解決這個問題?

+0

,因爲沒有協議的 – dfsq

回答

3

您是否試過http://api.openweathermap.org/data/2.5/forecast/daily - 將http://部分添加到您的資源網址中。它看起來像你當前的網址是相對於你的網站。

所以此:

$resource("api.openweathermap.org/data/2.5/forecast/daily", { callback: "JSON_CALLBACK" }, { get: { method: "JSONP" }}); 

成爲該

$resource("http://api.openweathermap.org/data/2.5/forecast/daily", { callback: "JSON_CALLBACK" }, { get: { method: "JSONP" }}); 
當然