【问题标题】:Openweather API Refusing ConnectionOpenweather API 拒绝连接
【发布时间】:2017-07-16 02:22:02
【问题描述】:

我确定这是我在阅读 API 文档时错过的内容 - 我正在尝试在 jquery 中对请求进行硬编码以调用 openweather API,因为页面是特定于地理的:

console.log('Connected to Script.js');
$(document).ready(weatherSettings);
function weatherSettings () {
  var config =
  {
    url: 'https://api.openweathermap.org/forecast',
    data: {
      id:'7281804',
      appid: 'MYID'
    }
  };
  $.ajax(config).done(displayMelbourneData);
  function displayMelbourneData(callback) {
    console.log(callback);
  }  
}

然而,我得到的错误是:net::ERR_CONNECTION_REFUSED,我终生无法弄清楚原因。

任何帮助将不胜感激。

【问题讨论】:

    标签: jquery openweathermap


    【解决方案1】:

    只需将您当前的 URL 更改为 http://api.openweathermap.org/data/2.5/forecast 就可以了。

    你可以直接在浏览器中试试这个(记得用你自己的API密钥更改YOURAPIKEY)

    http://api.openweathermap.org/data/2.5/forecast?id=7281804&appid=YOURAPIKEY

    以下是我尝试和工作的示例。顺便说一句,不要忘记用您自己的 API 密钥更改 YOURAPIKEY。

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <title></title>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
    </head>
    <body>
      <script>
    
        console.log('Connected to Script.js');
        $(document).ready(weatherSettings);
        function weatherSettings () {
          var config =
          {
            url: 'http://api.openweathermap.org/data/2.5/forecast',
            data: {
              id:'7281804',
              appid: 'YOURAPIKEY'
            }
          };
          $.ajax(config).done(displayMelbourneData);
          function displayMelbourneData(callback) {
            console.log(callback);
          }  
        }
      </script>
    </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 2016-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-21
      • 1970-01-01
      • 1970-01-01
      • 2017-08-08
      • 2013-01-03
      相关资源
      最近更新 更多