Q:

Codeigniter jquery ajax pagination

I get one tutorial over here
http://codeigniter.com/forums/viewthread/122597/P0/
everything is find but not the pagination link. 
here's my code
<script>
    ajax_paging = function()
    {
        $("p.pagination a").click(function() 
        {
            $.ajax({
            type: "GET",
            url: $(this).get(),
            success: function(html)
                     {
                         $("#display-content").html(html);
                     }
            });               
        });            
    return false;
    }; 
</script>

<?php 
    if($num_results == 0)
    {
        echo 'No data result, please insert one';
    }
    else
    {
?>
        <div id="display-content">
        <table width="100%">
        <tr>
            <th>CP code</th>
            <th>Code</th>
        </tr>
    <?php foreach($records as $row){ ?>
        <tr>
            <td align="center"><?php echo $row->created_date?></td>
            <td align="center"><?php echo $row->uid?></td>
        </tr>
    <?php }?>
</table>
 <p class="pagination">
 <?=$pagination?>
    </p>
    </div>
<?php } ?>

here the pagination HTML
    <p class="pagination">
     &nbsp;<strong>1</strong>&nbsp;
<a onclick="javascript:ajax_paging();return false;" href="http://bravonet.my/tombocrm/inside/home_fpr/5">2</a>&nbsp;
<a onclick="javascript:ajax_paging();return false;" href="http://bravonet.my/tombocrm/inside/home_fpr/10">3</a>&nbsp;
<a onclick="javascript:ajax_paging();return false;" href="http://bravonet.my/tombocrm/inside/home_fpr/5">&gt;</a>&nbsp;    
</p>

IWhen i try to click on the pagination link it works like normal link only. the javascript ajax occur error.
i am very weak in javascript. any help would be appreciated and thx in advanced.

A:

This is so easy to add ajax pagination in codeigniter  
//AJAX PAGINATION || GEETING URL FROM ON CLICK PAGE NO. IN PAGINATION
$(function(){
  $(document).on('click', ".pages a",function(){  // LOAD ON PAGE LOAD AND ON CLICK
   var urls = $(this).attr("href");

   $.ajax({
   type: "POST",
   url: urls,
   data:"",
   success: function(res){
      $("#ajaxComment").html(res);  //SET COMPLETE RESPONCE VALUE IN DIV
   }
   });

 return false;
});

});

Heading

A:

1 jquery .get() is for getting DOM elements so you don't need it here and $(this) inside $("p.pagination a").click() references  tag, so like in r.piesnikowski's comment replace $(this).get() with $(this).attr('href')
2 Don't put onclick="javascript:ajax_pagin();return false;" in your  tag, instead leave in your  tag this snippet (which adds onclick event handler to your  tags):
$(document).ready(function(){
  $("p.pagination a").click(function() {
    $.ajax({
      type: "GET",
      url: $(this).attr('href'),
      success: function(html){
        $("#display-content").html(html);
      }
    });               
    return false;
  });            
});

3 In your js code there was an error - return false was misplaced and the onclick event didn't return false itself, ajax_pagin did, that is why the link worked normally.

