码迷,mamicode.com
首页 > Web开发 > 详细

jquery,ajax页面内点击加载内容

时间:2019-10-20 18:13:25      阅读:33      评论:0      收藏:0      [点我收藏+]

标签:data   var   enc   fir   show   cli   app   esc   product   

<div class="chanppin_content" id="listsBox"></div>

<a id="moreClick">查看更多</a>
<script type="text/javascript">
    var page = 1;
    var pageCount = 0;
    loadMore();
    function loadMore(){
        $.getJSON({:U("loadMore")},{p:page}, function(d){
            pageCount = d.pageCount;
            $.each(d.lists, function(k, v){
                $(#listsBox).append(<div class="chanppin_content_li wow zoomIn animated" data-wow-duration="1s" data-wow-delay=".2s">                    <a href="+v.url+">                        <div class="img">                            <img src="+v.pic_text+" >                        </div>                        <div class="text">                            <p>+v.title+</p>                        </div>                    </a>                </div>);
            });
            
        });
    }


    $(#moreClick).click(function(){
        if(page< pageCount){
            page++;
            loadMore();
        }else{
            alert(没有了);
        }
    });
</script>
function loadMore(){
        $where = ‘`id` >0‘;
        if(I(‘get.cid‘)){
            $where .= ‘ and `cat_id` = ‘.I(‘get.cid‘);
        }
        $count =  M(‘Xiangce‘)->where($where)->count();

        $pageSize = 6;
        $pageCount = ceil($count/$pageSize);

        $page = new \Think\Page($count,$pageSize);
        $page->setConfig(‘theme‘, "%UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% <label class=‘f_14 clr_6‘>共%TOTAL_ROW%条</label>");
        $this->page = $page->show();
        $lists = M(‘Xiangce‘)->where($where)->order(‘order_id desc,id desc‘)->limit($page->firstRow.‘,‘.$page->listRows)->select();
        foreach($lists as $k=>$v){
            $lists[$k][‘url‘] = U(‘Product/view‘, [‘id‘=>$v[‘id‘]]);
            $lists[$k][‘pic_text‘] = __ROOT__.‘/Attached/‘.$v[‘pic‘];
        }

        die(json_encode([‘lists‘=>$lists, ‘pageCount‘=>$pageCount]));
    }

 

jquery,ajax页面内点击加载内容

标签:data   var   enc   fir   show   cli   app   esc   product   

原文地址:https://www.cnblogs.com/ximishuier/p/11708081.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有 京ICP备13008772号-2
迷上了代码!