<input type="text" id="keyword"><button id="so">搜索</button>
<ul id="data"></ul>
<button class="ajaxMore" style="display: none">加载更多</button>
<script type="text/javascript">
let curpage = 1;
let limit=15;
let sum =0;
let _fields='id,tid,title,keywords,description,litpic,body,htmlurl,target,addtime';
let _serUrl ="/GetData/getDataSearch.html";
let _model='article';
let _key='232323';
let _word = '';
let _title = 'title';
$("#so").click(function(){
    _word = $("#keyword").val();
    let  html='';
    $.ajax({
     url:_serUrl,
     dataType:"json",
     async:true,
     data:{model:_model,key:_key,search:_title,word:_word,fields:_fields,limit:limit,page:curpage},
     type:"POST",
     success:function(r){
         console.log(r);
            sum = r.sum;
             if(sum>=1&&sum<=limit){
                 $(".ajaxMore").show().html('没有更多了!');
            }else if(sum>limit){
                  $(".ajaxMore").show();
            }else{
                $(".ajaxMore").show().html('无相关数据');
            }
            $("#data").html('');
                for(const item of r.data){
                  html+=`<li><h4>${item.title}</h4></li>`;
                }
           $("#data").html(html);    
    },
     error:function(){

    }
    })

})
    
$(".ajaxMore").click(function(){
        curpage++;    
        let html = '';
        $.ajax({
             url:_serUrl,
             dataType:"json",
             async:true,
             data:{model:_model,key:_key,search:_title,word:_word,fields:_fields,limit:limit,page:curpage},
             type:"POST",
             success:function(r){
                 if(r.data.length>0){
                     let allpage = r.allpage;
                    if(curpage<=allpage){
                        if(r.data.length<limit){
                           $(".ajaxMore").text('没有更多了!');
                         };
                        for(const item of r.data){
                              html+=`<li><h4>${item.title}</h4></li>`
                         }
                        $("#data").append(html);
                         

                       }
               }

             }
        })


})


</script>

标签: 极致cms

您需要先登录才能发表评论。