codeigniter jQuery的AJAX分页 [英] Codeigniter jquery ajax pagination

查看:117
本文介绍了codeigniter jQuery的AJAX分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到一个教程在这里 HTTP://$c$cigniter.com/forums/viewthread/122597/P0/

I get one tutorial over here http://codeigniter.com/forums/viewthread/122597/P0/

一切都找到,但不是分页链接。

everything is find but not the pagination link.

这是我的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 } ?>

下面的分页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我尝试点击它的工作原理是再正常不过的链接分页链接。 javascript的AJAX出现的错误。

IWhen i try to click on the pagination link it works like normal link only. the javascript ajax occur error.

我是非常薄弱的​​JavaScript。任何帮助,将先进的AP preciated和THX。

i am very weak in javascript. any help would be appreciated and thx in advanced.

推荐答案

1 jQuery的获得()可以获取DOM元素,所以你不需要在这里和$(本)在$(p.pagination一个 )。单击()引用标记,所以像在r.piesnikowski的评论替换$(本)获得()与$(本).attr(HREF')

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,不要放的onclick =JavaScript的:ajax_pagin();返回false;在你的标签,而不是你的标签此代码段(添加onclick事件处理程序的标签)离开:

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在你的js code有一个错误 - 返回false是没有道理的和onclick事件没有返回false本身,ajax_pagin做,这就是为什么链接正常工作

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.

这篇关于codeigniter jQuery的AJAX分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆