试图访问天气API和显示名称和天气只是以下代码是正确的

时间:2017-08-24 06:00:05

标签: javascript jquery html css

var api="https://fcc-weather-api.glitch.me/api/current?";
function getWeather(lat,lon){
  var ustr = api + lat + "&" + lon;
  $.ajax({
    url: ustr, success:function(result){
      $("#place").text(result.name+",");
      $("#country").text(result.sys.country);
    }
  });
}
$( document ).ready(function(){
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function (position) {
      var lat = "lat=" + position.coords.latitude;
      var lon = "lon=" + position.coords.longitude;
      getWeather(lat, lon);
    });
  } else {
    $("#place").html("Geolocation is not supported by this browser.");
  }

})

无法从此JavaScript获取姓名和国家/地区,请提供帮助 我甚至试过j son功能,但dint显示任何结果

0 个答案:

没有答案