ajax分页

     
    //加载数据
     function loadList(){
          var url = "../../exam_questions/json?type=" + typ + "&page=" + page;
          $.ajax({
              type: 'GET',
              url: url,
              success:function(data){
                   $(".layui-table").find("th").find("input").prop("checked",false);        /*取消表头选框选定状态    */      
                    var html = template('list', data);
                   $("#type-list").html(html);    
                   $("#pagination").pagination({    
                       totalData: data.page.total,
                       showData: data.page.page_size,
                       current:data.page.page,     
                       callback: function(p){
                           page = p.getCurrent();
                           loadList(typ);
                       }
             
                   });
                 /*  勾选试题回显*/
                      $("#type-list").find("tr").each(function(){
                          var tr = $(this);
                          var id = tr.attr("data-id");
                          var hidden = $("#hidden").find("input[data-id="+ typ +"]");
                          var content = hidden.val();
                          if(content!==""){
                              var num = content.indexOf(id);
                              if(num>=0){
                                   tr.find("input").prop("checked",true);
                                  }                    
                              }

                           });
                   
              }              
          });

     }
      
/*     设置考卷获取数据*/
     $("#topic-selection").on("click","button",function(){
         $(this).removeClass("gray").siblings().addClass("gray");     
         typ = $(this).attr("data-id");
         page = 1;
         loadList();    
     });

typ  和  page  是全局的, 用来保存当前的状态。


loadList 与其它操作都无关, 只是从这里取数据来接数据



点击切换,,只是在切换 typ 状态



点击分页,只是在切换  page 的状态



然后,再调用一下 loadList 就行了 
原文地址:https://www.cnblogs.com/linsx/p/6952021.html