2016-08-22 107 views
5

我试图用AngularJS来从openweathermap.org API一个JSON,但我的请求返回错误代码404。这里是我的代码:AngularJS http.get返回404

 
$scope.key = "XXXXXXXXXXXXX";

$scope.search = "Rouen"; $scope.url= "api.openweathermap.org/data/2.5/weather?q=" + $scope.search + "&APPID=" + $scope.key; $scope.fetch = function(){ $http.get($scope.url) .then(function(response){ $scope.res = response.data; $scope.status= response.status;}, function errorCallback(response) { alert(response.status);});

我已经尝试请求另一个网址,并且得到了与此相同的问题:http://www.omdbapi.com/?t=Sherlock%20Holmes&tomatoes=true&plot=full

有人对这里有什么错误有所了解吗?

请原谅我,如果这是显而易见的,我是AngularJS的全新产品,并且我还没有在其他主题上找到任何解决方案。

非常感谢您的回答!

+0

哪里是'//'? – epascarello

+0

这是错误,缺乏http://,愚蠢的^^谢谢 –

回答

2

我看到的唯一错误是,你没有设置http:之前的URL

//这是对我的铬响应

Request URL:http://api.openweathermap.org/data/2.5/weather?q=Rouen&APPID=XXXXXXXXXXXXX 
Request Method:GET 
Status Code:401 Unauthorized 
Remote Address:192.241.169.168:80 
当然

一个未经授权的APPID不是401有效

+0

干得好,那是我的错误,现在起作用了,真是白痴!非常感谢 –

+0

接受答案 –