首页 话题 小组 问答 好文 用户 我的社区 域名交易 唠叨

[分享]帝国cms7.5无刷新 Ajax 点击加载更多列表信息源代码

发布于 2024-11-18 21:02:01
0
176

1.页面需要引入jquery.js文件2. 列表页合适位置添加以下代码(我是在中添加的,关键是要添加代码: id"showajaxnews",这样点击 点击添加更多 按钮时,列表内...

1.页面需要引入jquery.js文件

2. 列表页合适位置添加以下代码(我是在<ul>中添加的,关键是要添加代码: id="showajaxnews",这样点击 点击添加更多 按钮时,列表内容就被添加到了<ul class="slLis wrap" id="showajaxnews">下面)

    我的是这样的:<ul class="slLis wrap" id="showajaxnews">,大家对照自行修改。

3. 在列表页加上 点击加载更多 按钮。

   我的是这样的:<a class="load_more_btn" id="loadmore" target="_self" style="display: block;">点击加载更多</a>

4. 在列表页</body>前加上以下js代码。

      说明:

  (1). 代码中 'limit':25 , 25需修改为你想点击一次加载更多时加载的条数。通常要修改成和  系统后台 → 系统设置 → 系统参数设置 → 信息设置 中的:前台结合项列表每页显示 25 个信息   这个数一样

  (2). 代码中有 <img src="/skin/list/loaduai.gif" width=20/>&nbsp;页面加载中...,所以需要在 /skin/list/ 下添加这个表示正在加载的GIF动画图标  loaduai.gif 。你也可以把图标放在别的位置,但要修改相应的这个 /skin/list/loaduai.gif 代码。


<script>
$(function(){   
     var i = 1; //设置当前页数     
    $('#loadmore').click(function(){
        $.ajax({
        url : '/e/action/getmorearticle.php',
                type:'POST',
                 data:{"next":i,'classid':'[!--self.classid--]','action':'getmorenews','limit':25,'small_length':120},
            dataType : 'html',
        beforeSend:function(){
                $("#loadmore").show().html('<img src="/skin/list/loaduai.gif" width=20/>&nbsp;页面加载中...');
           $('#loadmore').attr('disabled','disabled');
        },
            success : function(data){
           if(data){
               $("#showajaxnews").append(data);
                          $("#loadmore").removeAttr('disabled');
              $("#loadmore").html('点击加载更多');
                 i++;
            }else{
                $("#loadmore").show().html("已全部加载完毕!");
                        $('#loadmore').attr('disabled','disabled');
                return false;
            }      
           }
        });
    });
});
</script>

5.  在/e/action/下添加文件 getmorearticle.php(修改 $limit=25; 中的25和 js中的数字一样)

    getmorearticle.php内容如下:


<script>
$(function(){   
     var i = 1; //设置当前页数     
    $('#loadmore').click(function(){
        $.ajax({
        url : '/e/action/getmorearticle.php',
                type:'POST',
                 data:{"next":i,'classid':'[!--self.classid--]','action':'getmorenews','limit':25,'small_length':120},
            dataType : 'html',
        beforeSend:function(){
                $("#loadmore").show().html('<img src="/skin/list/loaduai.gif" width=20/>&nbsp;页面加载中...');
           $('#loadmore').attr('disabled','disabled');
        },
            success : function(data){
           if(data){
               $("#showajaxnews").append(data);
                          $("#loadmore").removeAttr('disabled');
              $("#loadmore").html('点击加载更多');
                 i++;
            }else{
                $("#loadmore").show().html("已全部加载完毕!");
                        $('#loadmore').attr('disabled','disabled');
                return false;
            }      
           }
        });
    });
});
</script>
评论
一个月内的热帖推荐
拿破轮子
Lv.1普通用户

84

帖子

19

小组

240

积分

赞助商广告
站长交流