I am trying to create a dynamic pagination system for my website and I've decided on using ajax callback function to dynamically show the comments when the user clicks on different page elements.. So I'm pasting the code below as an example as to how I am doing it...I would like to ask you guys if I'm doing it right or if their is any better way to do it please point me to the right direction:
javascript :
$(document).ready(function(){
$(".pages").click(function(){
var pageno=$(this).attr("id").slice(4,8);//slicing out numbers from the id i.e "1" from "page1"
$.get("news.php", { pageno: pageno},
function(data){
$("#comments").html(data);
});
});
});
html:
<div>
<span id="page1" class="pages" >1</span>
<span id="page2" class="pages" >2</span>
<span id="page3" class="pages" >3</span>
</div >
<div id="comments">
</div>
php:
<div><?php echo $_REQUEST['pageno'];?></div>