2016-05-26 9 views
0

私はYQLを使ってYahooから天気を取り出そうとしています。しかし何らかの理由で何も返されませんが、Select文でURLを手動で呼び出そうとしましたが、必要な結果が返されます。誰かが自分のコードで間違っていたデバッグを助けることができますか?jQueryとYQLを使ってYahoo Weatherを抽出する

$(function(){ 

    var loc1 = 'Singapore, Singapore'; // Singapore 
    var u = 'c'; 
    var query1 = "SELECT * FROM weather.forecast WHERE woeid in (select woeid from geo.places(1) where text='" + loc1 + "' AND u='" + u + "'"; 
    var cacheBuster = Math.floor((new Date().getTime())/3600/1000); 

    var url1 = 'https://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent(query1) + '&format=json&_nocache=' + cacheBuster; 

    window['wxCallback1'] = function(data) { 
     var info = data.query.results.channel; 
     $('#wxIcon1').append('<img src="weathericon/' + info.item.condition.code + '.gif" width="52" height="52" title="' + info.item.condition.text + '" /><br>' + info.item.condition.text + '<br>'); 
     $('#wxTemp1').html(info.item.forecast[0].low + '<font style="FONT-WEIGHT:normal; FONT-SIZE:12px">&deg;' + (u.toUpperCase()) + '</font>' + ' - ' + info.item.forecast[0].high + '<font style="FONT-WEIGHT:normal; FONT-SIZE:12px">&deg;' + (u.toUpperCase()) + '</font>'); 
     $('#wxHum1').html(info.atmosphere.humidity + '<font style="FONT-WEIGHT:normal; FONT-SIZE:12px">%</font>'); 

    }; 
    $.ajax({ 
     url: url1, 
     dataType: 'jsonp', 
     cache: true, 
     jsonpCallback: 'wxCallback1' 
    }); 

}); 

答えて

0

問題を見つけるために管理しました。以前は除外されていたHTMLセクションを含む完全な作業コードがあります。条件コードは、表示されるグラフィックファイルを示すことに注意してください。 https://www.igorkromin.net/index.php/2015/09/11/yahoo-weather-condition-code-to-weather-icons-font-mapping/

<!doctype html> 
<html lang="en"> 
    <HEAD> 
<META http-equiv="Page-Enter" CONTENT="RevealTrans(Duration=3,Transition=23)"> 
<title>selWeather</title> 

</HEAD> 

<body topmargin="0" leftmargin="0" style="BACKGROUND-COLOR:transparent"> 

<table cellpadding="1" cellspacing="1" border="0" width="194"> 
     <tr> 
     <td colspan="2" valign="middle" bgcolor="#d0690a"> 
      <font style="FONT-SIZE:10px; COLOR:#ffffff; FONT-FAMILY:Arial, helvtical, verdana, tahoma"> 
      SINGAPORE<br> 
      </font> 
     </td> 
     </tr> 
     <tr> 
     <td rowspan="3" valign="middle" align="center" width="50%"> 
      <font style="FONT-SIZE:10px; COLOR:#000000; FONT-FAMILY:Arial, helvtical, verdana, tahoma"> 
      <span id="wxIcon1"></span> 
      </font><br> 
     </td> 
     <td valign="middle" align="center"> 
      <font style="FONT-SIZE:10px; COLOR:#000000; FONT-FAMILY:Arial, helvtical, verdana, tahoma"> 
      TEMPERATURE</font><br> 
      <font style="FONT-WEIGHT:bold; FONT-SIZE:20px; COLOR:#000000"> 
      <span id="wxTemp1"></span> 
     </td> 
     </tr> 
     <tr> 
     <td height="1" bgcolor="#999999"></td> 
     </tr> 
     <tr> 
     <td valign="top" align="center"> 
      <!-- <hr style="WIDTH: 90%; COLOR: #999999; HEIGHT: 1px"> --> 
      <font style="FONT-SIZE:10px; COLOR:#000000; FONT-FAMILY:Arial, helvtical, verdana, tahoma"> 
      HUMIDITY</font><br> 
      <font style="FONT-WEIGHT:bold; FONT-SIZE:20px; COLOR:#000000"> 
      <span id="wxHum1"></span></font><br> 
     </td> 
     </tr> 
     </table> 

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script> 

<script type="text/javascript"> 

$(function(){ 

    var loc1 = 'Singapore, Singapore'; // Singapore 
    var u = 'c'; 
    var query1 = "SELECT * FROM weather.forecast WHERE woeid in (select woeid from geo.places(1) where text='" + loc1 + "') AND u='" + u + "'"; 
    var cacheBuster = Math.floor((new Date().getTime())/3600/1000); 

    var url1 = 'https://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent(query1) + '&format=json&_nocache=' + cacheBuster; 

    window['wxCallback1'] = function(data) { 
     var info = data.query.results.channel; 
     $('#wxIcon1').append('<img src="weathericon/' + info.item.condition.code + '.gif" width="52" height="52" title="' + info.item.condition.text + '" /><br>' + info.item.condition.text + '<br>'); 
     $('#wxTemp1').html(info.item.forecast[0].low + '<font style="FONT-WEIGHT:normal; FONT-SIZE:12px">&deg;' + (u.toUpperCase()) + '</font>' + ' - ' + info.item.forecast[0].high + '<font style="FONT-WEIGHT:normal; FONT-SIZE:12px">&deg;' + (u.toUpperCase()) + '</font>'); 
     $('#wxHum1').html(info.atmosphere.humidity + '<font style="FONT-WEIGHT:normal; FONT-SIZE:12px">%</font>'); 

    }; 
    $.ajax({ 
     url: url1, 
     dataType: 'jsonp', 
     cache: true, 
     jsonpCallback: 'wxCallback1' 
    }); 

}); 

</script> 
</body> 
</HTML> 
関連する問題