$("#get").click(function() { var url = "https://www.google.co.jp/"; // いいね取得 $.ajax({ url : 'https://graph.facebook.com/' + url, dataType : 'jsonp', success : function(json){ $('#facebook .count').text( json.shares || 0 ); } }); // ツイート取得 $.ajax({ url : 'http://urls.api.twitter.com/1/urls/count.json?url=' + url, dataType : 'jsonp', success : function(json){ $('#twitter .count').text( json.count || 0 ); } }); // はてぶ取得 $.ajax({ url : 'http://api.b.st-hatena.com/entry.count?url=' + url , dataType : 'jsonp', success : function(json){ $('#hatebu .count').text(json); } }); });
<p>googleのいいね数・ツィート数・はてぶ数をボタンクリックで表示</p> <button id="get">クリック!!</button> <div id="facebook">いいね: <span class="count"></span></div> <div id="twitter">ツイート: <span class="count"></span></div> <div id="hatebu">はてぶ: <span class="count"></span></div>