1

simpleweatherjsを使用して Web サイトに天気を表示したいのですが、うまくいきません。誰かが私が間違っていることを教えてもらえますか? ページは空白です。たとえば、行 $.simpleWeather({...}); の前にある場合。put $("#weather").html("test") とすると、この文は機能しますが、$.simpleWeather({...}); の下では機能しません。例に示されているように。

これが私のhtmlです:

<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Weather</title>
    <link rel="stylesheet" type="text/css" href="style.css">
    <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery.simpleWeather/2.5.0/jquery.simpleWeather.min.js"></script>
</head>
<body>

<div id="weather"></div>
<script>
// Docs at http://simpleweatherjs.com
$(document).ready(function() {
  $.simpleWeather({
    location: 'Austin, TX',
    woeid: '',
    unit: 'f',
    success: function(weather) {
      html = '<h2><i class="icon-'+weather.code+'"></i> '+weather.temp+'&deg;'+weather.units.temp+'</h2>';
      html += '<ul><li>'+weather.city+', '+weather.region+'</li>';
      html += '<li class="currently">'+weather.currently+'</li>';
      html += '<li>'+weather.wind.direction+' '+weather.wind.speed+' '+weather.units.speed+'</li></ul>';

      $("#weather").html(html);
    },
    error: function(error) {
      $("#weather").html('<p>'+error+'</p>');
    }
  });
});

</script>
</body>
4

3 に答える 3

3

ローカル ファイルからコードを実行していますか? つまり、ブラウザで c:\html\test.html (または同等のもの) に移動します。

これを実行してもうまくいかないように見えますが、HTMLファイルをWebサーバー(Tomcatを使用)でホストしてナビゲートするhttp://localhost:8080/html/test/htmlとうまくいきました。

編集:これは、JS Fiddleでもうまく機能する理由を説明します

于 2014-02-24T14:04:21.243 に答える
1

あなたの行をクリアしてみてください:

 <link rel="stylesheet" type="text/css" href="style.css">

そこに何かが隠されているのかもしれません。

または/および行を変更します: (ローカルの場合)

//query.yahooapis.com/v1/public/yql

  http://query.yahooapis.com/v1/public/yql
于 2014-02-24T13:44:30.020 に答える
0

ロードできないというコンソールエラー

   //query.yahooapis.com/v1/public/yql.....

したがって、URL の前に http または https を付けます。

    https://query.yahooapis.com/v1/public/yql.....
于 2014-08-11T07:44:55.117 に答える