使用OpenWeatherMap进行jQuery ajax调用-net :: ERR_CONNECTION_REFUSED [英] jQuery ajax call with OpenWeatherMap - net::ERR_CONNECTION_REFUSED
问题描述
我想从OpenWeatherMap API获取基于纬度和经度的天气,但是却出现了错误
I want to get weather from OpenWeatherMap API based on latitude and longitude, but I'm getting error
net :: ERR_CONNECTION_REFUSED
net::ERR_CONNECTION_REFUSED
项目在codepen.io上
Project is on codepen.io
var appid = "myID";
function getLocation() {
$.getJSON('https://geoip-db.com/json/geoip.php?jsonp=?')
.done (function(location)
{
$('.country').html(location.country_name);
$('.city').html(location.city);
var lat = location.latitude;
var lon = location.longitude;
var weatherLink = "https://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&appid=" + appid + "&callback=?";
$('body').append(weatherLink);
$.ajax({
url: weatherLink,
dataType: "jsonp",
success: function(response) {
$('body').append(response);
}
});
});
}
$(document).ready(function() {
getLocation();
});
我正在使用 https://geoip-db.com/来获取经度和纬度. URL(weatherLink)是正确的.完整错误:
I'm using https://geoip-db.com/ to get latitude and longitude. URL (weatherLink) is correct. Full error:
获取 https://api.openweathermap.org/data/2.5/weather?lat = 51.1& lon = 17.0333& appid = …0b9873ed& callback = jQuery22406914555127333375_1469796455615& _ = 1469796455617 净:: ERR_CONNECTION_REFUSED
GET https://api.openweathermap.org/data/2.5/weather?lat=51.1&lon=17.0333&appid=…0b9873ed&callback=jQuery22406914555127333375_1469796455615&_=1469796455617 net::ERR_CONNECTION_REFUSED
推荐答案
您的APPid错误,只需注册一个帐户并从站点获取密钥.您需要一个有效的ID,否则它将拒绝您的连接.
Your APPid is wrong, just sign up for an account and get a key from the site. You need a valid ID or it will refuse your connection.
http://openweathermap.org/appid#get
将您的代码笔链接到我,如果您愿意,我可以仔细看看.
link me your codepen and I can take a closer look if you'd like.
此外,如果您想从网站上添加信息,则需要指定所需的参数,否则您将一无所获.
Also, if you want to append the information from the site, you need to specify the parameters you want, otherwise your going to get a bunch of nonsense.
这篇关于使用OpenWeatherMap进行jQuery ajax调用-net :: ERR_CONNECTION_REFUSED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!