OpenWeatherMap.ORG API-$ .getJSON不起作用,我没有收到任何数据

埃利·范·洛克(Eli Van Rock)

我正在尝试使用Providen api连接到openweather.org的测试代码。

如果我使用浏览器访问网址:

http://api.openweathermap.org/data/2.5/weather?id=2172797&APPID=35000cdad97645316c048563e4183021

然后,我得到正确的Json:{“ coord”:{“ lon”:145.77,“ lat”:-16.92},“ weather”:[{“ id”:803,“ main”:“ Clouds”,“ description “:”碎云“,” icon“:” 04n“}],” base“:”站点“,” main“:{” temp“:289.26,” pressure“:1013,”湿度“:93,” temp_min “:289.26,” temp_max“:289.26},” wind“:{” speed“:1.61,” deg“:116.5},” rain“:{” 3h“:0.03},” clouds“:{” all“: 76},“ dt”:1474367584,“ sys”:{“ type”:3,“ id”:10843,“ message”:0.1585,“ country”:“ AU”,“ sunrise”:1474315673,“ sunset”: 1474359164},“ id”:2172797,“名称”:“ Cairns”,“鳕鱼”:200}

问题是当我使用jquery的$ .getJSON时,我看不到任何数据。

这是为什么 ?如何解决?

JS:

$(document).ready(function(){

  var api = 'http://api.openweathermap.org/data/2.5/weather?id=2172797&APPID=35000cdad97645316c048563e4183021';

   $.getJSON(api, {format:'json'},function(data){console.log(data.coord.lon)});


});

CodePen:https://codepen.io/elivanrock/pen/zKoYEj editors = 1011

提前致谢!

斯科巴利奇

您可以从openweathermap.com使用JSONp获取数据,只需通过以下方式添加回调函数即可:

http://api.openweathermap.org/data/2.5/weather?id=2172797&APPID=35000cdad97645316c048563e4183021&callback=myfunc

下面的例子:

$.ajax({
    url: "http://api.openweathermap.org/data/2.5/weather",
    jsonp: "callback",
    dataType: "jsonp",
    data: {
        id: "2172797",
        APPID: "35000cdad97645316c048563e4183021"
    },
    success: function( response ) {
        console.log( response ); // server response
        $('.current').html('<img src="http://openweathermap.org/img/w/' + response.weather[0].icon + '.png" /> ' + response.weather[0].main);
    }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="current"></div>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用经纬度参数时,按下openweathermap API后未收到任何数据

来自分类Dev

错误401:未经授权,即使在使用www.openweathermap.org时使用API密钥后仍会收到

来自分类Dev

无法从openWeatherMap API JavaScript获取数据

来自分类Dev

OpenWeatherMap API与Wunderground API?

来自分类Dev

使用OpenWeatherMap API密钥

来自分类Dev

免费使用openweathermap API

来自分类Dev

OpenWeatherMap API SWIFT

来自分类Dev

从 OpenWeatherMap Api 崩溃应用程序获取 NSURLSESSION 数据

来自分类Dev

如何使用openweathermap API密钥?

来自分类Dev

OpenWeatherMap API,如何获取温度?

来自分类Dev

OpenWeatherMap API HTTPS拒绝JavaScript

来自分类Dev

Openweathermap API Forecast 访问数组

来自分类Dev

带有OpenWeatherMap切片图层叠加层的Google Maps Javascript API

来自分类Dev

使用openweathermap api显示当地天气

来自分类Dev

天气API(openweathermap)显示温度错误

来自分类Dev

OpenWeatherMap API返回“未定义”

来自分类Dev

使用openweathermap api显示当地天气

来自分类Dev

移动应用程序的openweathermap API问题

来自分类Dev

使用openweathermap API进行温度转换

来自分类Dev

显示openweathermap API错误时出错

来自分类Dev

在 PHP 中使用 OpenWeatherMap 预报 API

来自分类Dev

Openweathermap API 调用响应错误的 json

来自分类Dev

我有来自OpenWeatherMap API的风向数据,该数据以0到360度表示。我想将其转换为文本格式

来自分类Dev

openweathermap api无效的api密钥错误[error401]

来自分类Dev

附近的API没有收到任何消息

来自分类Dev

Openweathermap API获得当天的高温和低温

来自分类Dev

如何使用 JSON (OpenWeatherMap) 在 C# 中使用 API 文档

来自分类Dev

如何计算openweathermap.org JSON中返回的摄氏温度?

来自分类Dev

如何使用JSON数据从OpenWeatherMap获得7天预报?

Related 相关文章

  1. 1

    使用经纬度参数时,按下openweathermap API后未收到任何数据

  2. 2

    错误401:未经授权,即使在使用www.openweathermap.org时使用API密钥后仍会收到

  3. 3

    无法从openWeatherMap API JavaScript获取数据

  4. 4

    OpenWeatherMap API与Wunderground API?

  5. 5

    使用OpenWeatherMap API密钥

  6. 6

    免费使用openweathermap API

  7. 7

    OpenWeatherMap API SWIFT

  8. 8

    从 OpenWeatherMap Api 崩溃应用程序获取 NSURLSESSION 数据

  9. 9

    如何使用openweathermap API密钥?

  10. 10

    OpenWeatherMap API,如何获取温度?

  11. 11

    OpenWeatherMap API HTTPS拒绝JavaScript

  12. 12

    Openweathermap API Forecast 访问数组

  13. 13

    带有OpenWeatherMap切片图层叠加层的Google Maps Javascript API

  14. 14

    使用openweathermap api显示当地天气

  15. 15

    天气API(openweathermap)显示温度错误

  16. 16

    OpenWeatherMap API返回“未定义”

  17. 17

    使用openweathermap api显示当地天气

  18. 18

    移动应用程序的openweathermap API问题

  19. 19

    使用openweathermap API进行温度转换

  20. 20

    显示openweathermap API错误时出错

  21. 21

    在 PHP 中使用 OpenWeatherMap 预报 API

  22. 22

    Openweathermap API 调用响应错误的 json

  23. 23

    我有来自OpenWeatherMap API的风向数据,该数据以0到360度表示。我想将其转换为文本格式

  24. 24

    openweathermap api无效的api密钥错误[error401]

  25. 25

    附近的API没有收到任何消息

  26. 26

    Openweathermap API获得当天的高温和低温

  27. 27

    如何使用 JSON (OpenWeatherMap) 在 C# 中使用 API 文档

  28. 28

    如何计算openweathermap.org JSON中返回的摄氏温度?

  29. 29

    如何使用JSON数据从OpenWeatherMap获得7天预报?

热门标签

归档