$_GET メソッドを介して、前のページのドロップダウン リストから 2 つのハッシュタグ変数 (サッカー チーム) を受け取ります。これらは、チーム 1 に関する最新のツイートを表示するために操作しようとしている JavaScript 変数に格納されています。
Twitterの検索URLの構成か、ツイートを取得する関数自体($.getJSON(url,function(tweet))のどちらかで(何も表示されていないので)苦労しているようです。とにかく、コードは以下のとおりです。ありがとう見るために;
<div id="mainContent">
<script type="text/javascript">
var team1, team2;
team1 = '<?php echo $_GET["team1"]; ?>';
team2 = '<?php echo $_GET["team2"]; ?>';
</script>
<div id="last-tweet">
</div>
<script type="text/javascript">
$(document).ready(function(){
var format='json'; // set format
var url='http://search.twitter.com/search.json?q=%23' + team1 + '&callback=?';
$.getJSON(url,function(results){ // get the tweets
$("#last-tweet").html(results[0].text); // get the first tweet in the response and place it inside the div
});
});
更新: 返された json ファイルをチェックアウトしましたが、おそらくデータを参照するために使用しているキーワードは、'tweet' ではなく 'results' である必要があるようです (例: results[0])。しかし、私はこれを調整しましたが、まだ運がありません。Firebug は「結果が未定義です」と報告します。
json ファイルのスニペットを以下に示します。
{"results":[{"from_user_id_str":"118766757","profile_image_url":"http://a0.twimg.com/profile_images/1128884063/ManchesterUnited07_normal.jpg","created_at":"Thu, 17 Mar 2011 11:02:21 +0000","from_user":"sarthak_dev90","id_str":"48338376365056000","metadata":{"result_type":"recent"},"to_user_id":null,"text":"#ificouldiwouldbringback Tevez to #MUFC. He made a difference almost every time he played.",