PHPとjQueryのAjaxを使って、サーバーから追加のコンテンツを読み込む機能を実装してみます。
このレッスンでは PHP 5.3 / jQuery 1.6.4 を使用しています。
$url = "http://api.twitter.com/1/statuses/user_timeline.json?screen_name=taguchi"; if ($_POST['max_id'] != '') { $url .= "&max_id=".$_POST['max_id']; }
foreach ($tweets as $i => $tweet) { if ($_POST['max_id'] != '' and $i == 0) { continue; } echo "<li data-status-id='".$tweet->id_str."'>".$tweet->text."</li>"; }
<script> function more() { var max_id = $('#tweets>li:last').data('status-id'); $.post('more.php', { max_id: max_id }, function(rs) { $("#tweets").append(rs); }); } $(function() { more(); }); </script>
補足情報 あわせて見ておきたいレッスンについて
・PHPの基礎
http://dotinstall.com/lessons/basic_php
・JavaScriptの基礎
http://dotinstall.com/lessons/basic_javascript
・jQueryの基礎
http://dotinstall.com/lessons/basic_jquery