$资源不发送GET请求

问题描述:

我试图发送一个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

您是否试过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" }}); 
当然