使用 getJSON 从 openweathermap.org 获取数据

Posted

技术标签:

【中文标题】使用 getJSON 从 openweathermap.org 获取数据【英文标题】:Fetch data from openweathermap.org using getJSON 【发布时间】:2020-07-22 22:16:53 【问题描述】:

我正在尝试使用 jQuery 函数 getJSON 从 openweathermap.org 获取数据,但出现了一些问题

var apiKey = "54df40e238084fbf095d3540271e48a0";
var URL = "api.openweathermap.org/data/2.5/weather?q=London&appid=" + apiKey;

$(document).ready(function() 

  $.getJSON(URL, function(data) 
    console.log(data);
  )


);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

【问题讨论】:

嗨,你能澄清一下这个问题吗?有什么问题? 这能回答你的问题吗? $.getJSON not working 【参考方案1】:

网址错误,你需要这样做。

var apiKey = "54df40e238084fbf095d3540271e48a0";
var URL = "https://api.openweathermap.org/data/2.5/weather?q=London&appid="+apiKey;

$(document).ready(function()

$.getJSON(URL,function(data)
    console.log(data);
)
);

希望这会有所帮助。

【讨论】:

以上是关于使用 getJSON 从 openweathermap.org 获取数据的主要内容,如果未能解决你的问题,请参考以下文章