美文网首页
自己写的pagination分页,ajax异步加载

自己写的pagination分页,ajax异步加载

作者: 睦邻量 | 来源:发表于2017-11-24 17:24 被阅读0次

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<!DOCTYPE html>

<html>

<head lang="en">

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<link rel="stylesheet" type="text/css" href="../plugin/page/pagination.css">

<!-- <link rel="stylesheet" type="text/css" href="../plugin/page/common.css"> -->

<!-- <link rel="stylesheet" type="text/css" href="../plugin/page/reset.css"> -->

    <style type="text/css">

    </style>

<title>用户注册及用户列表</title>

</head>

<body>

<!-- 用户列表展示 -->

<div>

  <table border="1px">

  <thead>

    <tr>

    <td width="40">主键</td>

    <td width="60">用户名</td>

    <td width="240">创建时间</td>

    </tr>

  </thead>

  <tbody id="user_tbody_id">

    <!-- js追加 -->

  </tbody>

  </table>

  <!-- 分页div -->

  <div class="M-box"></div>

</div>

</body>

<script src="../js/jquery-1.11.3/jquery.js" type="text/javascript" charset="utf-8"></script>

<script src="../plugin/page/jquery.pagination.js" type="text/javascript" charset="utf-8"></script>

<script type="text/javascript">

// pagination分页

// 加载用户列表

$(function(){

  paging();

});

function paging(page){

  $.ajax({

  url:"../user/getAllUser",

  type:"post",

  dataType:"json",

  data:{'page':page},

  success:function(data){

    $('#user_tbody_id').empty();

    if(data.status != 200){

    alert(data.msg);

    }else{

    var apiPage = data.item;

    if(apiPage.count == 0){

      alert("没有用户!")

    }else{

      $('.M-box').pagination({

          totalData:apiPage.count,

          showData:apiPage.size,

          current:apiPage.page,

          coping:true,

          homePage:'首页',

          endPage:'末页',

          prevContent:'上页',

          nextContent:'下页',

          callback: function(api){

            paging(api.getCurrent());

          }

      });

      zhuijiaUser(apiPage.item);

    }

    }

   

  },

  error:function(err){

    console.log(err);

    alert("error");

  }

  });

}

function zhuijiaUser(data){

  $.each(data,function(k,v){

  $('#user_tbody_id').append(

    '<tr>'+

    '<td>'+v.id+'</td>'+

    '<td>'+v.username+'</td>'+

    '<td>'+v.create_time+'</td>'+

    '</tr>'

  );

  });

}

</script>

</html>

相关文章

网友评论

      本文标题:自己写的pagination分页,ajax异步加载

      本文链接:https://www.haomeiwen.com/subject/nlufbxtx.html