从Api(使用Ajax)/ jQuery发送和获取数据的问题
问题描述:
需要帮助从此api获取数据; https://fcc-weather-api.glitch.me/ ...从Api(使用Ajax)/ jQuery发送和获取数据的问题
function findLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
$("#data").html("latitude: " + position.coords.latitude + "<br>longitude: "
+ position.coords.longitude);
});
与此代码我把用户的地理定位,然后我shoulduse然后送还给使用者的位置,适当的天气条件。
$.getJSON("https://fcc-weather-api.glitch.me/", function(data) {
var items = [];
$.each(data, function(longitude, lattitude) {
items.push("<li id='" + longitude + "'>" + lattitude + "</li>");
});
$("<ul/>", {
"temp": "",//Having trouble especially here, how to take data of weather from api
html: items.join("")
}).appendTo("#data");
});
}
return false;
}
$(function() {
$("button").on("click", findLocation);
});
问题是不能发送经度和采取lattitude,然后采取气象数据..
答
此代码可以帮助您:
fetch('https://fcc-weather-api.glitch.me/api/current?lat=35&lon=139')
.then((response) => response.json()).
.then((data) => /* data is the object u need */)
欢迎的话,请阅读有关如何帮助部分问问题 –
https://stackoverflow.com/help/how-to-ask – Lexi