私は、提供されたapiでopenweather.orgに接続するためのテストコードを試しています。
私は私のブラウザを使用してURLにアクセスする場合:
http://api.openweathermap.org/data/2.5/weather?id=2172797&APPID=35000cdad97645316c048563e4183021
その後、私は適切なJSONを取得: { "COORD":{ "経度":145.77、 "緯度": - 16.92 「雲」、「説明」、「雲が壊れている」、「アイコン」:「04n」}]、「ベース」:「駅」、「駅」、 "temp":289.26、 "pressure":1013、 "humidity":93、 "temp_min":289.26、 "temp_max":289.26}、 "wind":{"speed":1.61、 "deg" 1165}、 "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、 "name": "Cairns"、 "cod":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
ありがとう!
**ブラウザのを確認してください** コンソール。 HTTP-HTTPsの問題。 HTTP経由でcodepenをロードすると、コードが機能します。 – yuriy636
おかげでたくさんのユーリ! –