gpt4 book ai didi

javascript - 我试图从 Openweather API 获取响应,但收到 404

转载 作者:行者123 更新时间:2023-12-03 00:48:27 26 4
gpt4 key购买 nike

// MODULE
var weatherApp = angular.module('weatherApp', ['ngRoute', 'ngResource']);

// Directives
weatherApp.service('cityService', function() {
this.city = "New York, NY";
});

// Controller

weatherApp.controller('homeController', ['$scope','cityService', function($scope, cityService){
$scope.city = cityService.city;

$scope.$watch('city', function(){
cityService.city = $scope.city;
});
}]);

weatherApp.controller('forecastController', ['$scope', 'cityService', '$resource', function($scope, $resource, cityService){
$scope.city = cityService.city;
$scope.weatherApi = $resource('http://api.openweathermap.org/data/2.5/forecast', {
callback: 'JSON_CALLBACK'
}, {get: { method: 'JSONP'}});


$scope.weatherResult = $scope.weatherApi.get({
q: $scope.city,
cnt: 2,
appid: 'b0a06997003bb34ff74635549a8bfd0e'
});
console.log($scope.weatherResult);
}]);

最佳答案

根据文档https://openweathermap.org/current#name ,您不应传递州名称,而应传递城市名称和可选的国家/地区名称。因此,http://api.openweathermap.org/data/2.5/forecast?appid=XXX&q=New%20York,%20US有效,但是 http://api.openweathermap.org/data/2.5/forecast?appid=XXX&q=New%20York,%20NY没有。有趣的是,http://api.openweathermap.org/data/2.5/forecast?appid=XXX&q=New%20York,%20NY,%20US也有效,尽管它看起来没有记录。

关于javascript - 我试图从 Openweather API 获取响应,但收到 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53149267/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com