【问题标题】:AngularJS http.get returns 404AngularJS http.get 返回 404
【发布时间】:2016-08-22 01:20:34
【问题描述】:

我正在尝试使用 AngularJS 从 openweathermap.org API 获取 JSON,但我的请求返回错误代码 404。这是我的代码:

$scope.key = "XXXXXXXXXXXX"; $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 的新手,我还没有找到其他主题的任何解决方案。

提前感谢您的回答!

【问题讨论】:

  • // 在哪里?
  • 这是错误,缺少http://,笨^^谢谢

标签: javascript angularjs http-status-code-404


【解决方案1】:

我看到的唯一错误是您没有在 url 之前设置 http://

这是我的 chrome 上的响应

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

当然是 401 Unauthorized 导致 APPID 无效

【讨论】:

  • 干得好,这是我的错误,现在可以了,真是个白痴!非常感谢
猜你喜欢
  • 2014-08-12
  • 2018-06-04
  • 2016-07-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-29
相关资源
最近更新 更多