- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在制作一个使用地理位置和搜索功能的天气应用程序。
地理定位功能正常,但用户搜索失败;控制台中的错误是:GET {api url} 404(未找到)。
首先,不起作用的功能:
function getWeatherWithUserInput() {
return new Promise(function(resolve, reject) {
var location = $("#location").val().trim();
var widget = Mixcloud.PlayerWidget(document.getElementById('my-widget-iframe'));
var weatherCSQueryURL = "http://api.openweathermap.org/data/2.5/weather?q=" + location + "=&appid=" + WeatherAPIKey;
$.ajax({
url: weatherCSQueryURL,
method: "GET"
}).done(function(response) {
//$(".city").html("<h1>" + response.name + " Weather </h1>");
$(".wind").html("<h1>" + response.name + "</h1>");
//$(".humidity").html("Humidity: " + response.main.humidity);
//var f_temp = 9/5*(response.main.temp-273)+32;
//$(".temp").html("Temperature (F) " + Math.floor(f_temp));
resolve(response.weather[0].id);
});
});
};
现在这个功能可以工作了:
function getWeatherWithGeo() {
return new Promise(function(resolve,reject) {
getGeoLocationGoogle()
.then(function(response) {
var lat = response.location.lat;
var lon = response.location.lng;
var weatherLLQueryURL = "http://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&appid=" + WeatherAPIKey;
$.ajax({
url: weatherLLQueryURL,
method: "GET"
}).done(function(response) {
$(".wind").html("<h1>" + response.name + "</h1>");
resolve(response.weather[0].id);
});
})
})
}
我似乎找不到区别,为什么一个可以工作,而另一个却不能。欢迎任何建议!
最佳答案
正确的网址应该是:
var weatherCSQueryURL = "http://api.openweathermap.org/data/2.5/weather?q=" + location + "&appid=" + WeatherAPIKey;
位置后面的 =
符号要求另一个值并告诉 ajax 请求该位置将是一个参数。
关于javascript - openweather API 的 GET 请求不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47587849/
你好,我尝试遵循这个manual采取Python开放天气API 这里是示例手册代码: import openweather from datetime import datetime # create
我制作了一个使用 p5.js 的天气预报网络应用程序。它在我的本地主机上完美运行。为什么这个问题不断出现在 github 页面上: Mixed Content: The page at '' was
我尝试在 Tkinter 中创建一个下拉框。我希望每次我选择一个国家并单击左侧按钮时,它都会显示我选择的国家的天气。显然,我必须手动更改这行代码(在定义天气函数中)weather_status = o
我刚开始学习 Swift 和 iOS,我的天气应用程序出现问题。我正在尝试获取天气数据并在控制台中打印,但仍然是零,我不知道可能出了什么问题。我试图更改模型,粘贴所有 url,但仍然为零。有时app发
这个问题已经有答案了: What is the scope of variables in JavaScript? (27 个回答) 已关闭 3 年前。 我正在构建一个时间和天气应用程序。我有两个功能
我读过很多类似的主题,但它们没有帮助.. 尝试访问此 JSON 对象.. { "coord": { "lon": -83.9, "lat": 33.99
如何让 mu openweather API 与地理定位一起使用?这是我当前的 html 代码:
我找到并修改了简单的代码,以使用 openweather 和 json 格式在 Python 中获取天气状况。但是我有一个问题——我怎么能说这个城市是不正确的呢? 我的意思是,即使我经过了一个错误的、
好吧,我遇到了一些情况,并且在理解如何从 API 返回的 JSON 中提取值方面遇到了障碍。我有以下代码: import requests import json weather_results =
我想从 Openweather API 解析 JSON。 Openweather URL 是:http://samples.openweathermap.org/data/2.5/weather?q=
我的任务是通过 API 显示天气预报。 我有以下代码,但无法显示数据。我今天刚刚开始学习 AngularJS 并使用 API,因此我们将不胜感激!具体来说,我的代码有什么问题导致天气数据无法显示? 这
我正在制作一个使用地理位置和搜索功能的天气应用程序。 地理定位功能正常,但用户搜索失败;控制台中的错误是:GET {api url} 404(未找到)。 首先,不起作用的功能: functio
我正在编写一些 JavaScript 以从包含名称、经度、纬度和 openweather API 调用的 JSON 中提取信息。我需要的是将 API 信息从 API 调用中获取到 HTML 页面中,以
// MODULE var weatherApp = angular.module('weatherApp', ['ngRoute', 'ngResource']); // Directives we
我正在创建一个应用程序,该应用程序使用 JSON 从 OpenWeather 的 API 中提取天气信息。我嵌套了“IF”语句,用于构建当前天气的字符串。目标是构建一串“当前天气(描述),温度为 (t
我正在使用 Swift 调用 Openweather map API,我需要从响应中返回一个特定值作为字符串。 但是,当我尝试返回值时出现错误,因为 JSON 不可转换为字符串。 func callW
我正在尝试使用 Android studio 和 Java 构建一个简单的天气预报应用程序。我按照此处的一些说明( https://www.androdocs.com/java/creating-an
我正在使用 DataTables并想在其中显示我的城市数据,但我没能做到。 例如如果我调用this URL然后我以 JSON 格式获取城市数据(来自 openweathers map api)。我只想
extern crate openweather; use openweather::LocationSpecifier; static API_KEY: &str = "e85e0a3142231d
我从 openweather api 获取一个对象,该对象包含 40 个对象的数组,其中包含 5 天的天气预报,间隔 3 小时。我在 Angular 2 应用程序中显示这 5 天的天气预报时遇到问题。
我是一名优秀的程序员,十分优秀!