通过ajax获取数据的分页插件的使用、jquery.paginate.js 还有搜索
2018-03-14 11:56
1006 查看
页面效果
接口回传的数据
html内容
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link href="js/jPaginate/pagination.css" rel="stylesheet"/>
</head>
<body>
<div class="search">
<input id="contaKeyword" type="text" placeholder="请输入机构或者学校名称进行搜索">
<input id="contaBtnSearch" type="button" value="Go">
</div>
<div class="conta_table_content">
<table border="0" cellspacing="0" cellpadding="0" class="conta_table_list" id="contaUnselectTableList">
<!-- 所有内容放在这里 -->
</table>
<div id="resourcePagination" class="pagination"></div> <!-- 分页效果 -->
</div>
<script src="js/jquery-3.1.1.min.js"></script>
<script src="js/jPaginate/jquery.paginate.js"></script>
<script>
//接口回传的数据:
//0 : {areaCode: "460205", cityCode: "460200", orgCode: "1146002201",…}
//1 : {areaCode: "460204", cityCode: "460200", orgCode: "2146000443",…}
//2 : {areaCode: "460204", cityCode: "460200", orgCode: "2146000297",…}
//3 : {areaCode: "460204", cityCode: "460200", orgCode: "3146000100",…}
//4 : {areaCode: "460205", cityCode: "460200", orgCode: "1146000083",…}
//5 : {areaCode: "460205", cityCode: "460200", orgCode: "1146002265",…}
//6 : {areaCode: "460205", cityCode: "460200", orgCode: "2146000340",…}
//7 : {areaCode: "460203", cityCode: "460200", orgCode: "3146000092",…}
//8 : {areaCode: "460202", cityCode: "460200", orgCode: "1146003246",…}
//9 : {areaCode: "460203", cityCode: "460200", orgCode: "1146001495",…}
//pageSize : 10
//totalPage : 32
//totalRecord : 311
function page(currentPage){ //currentPage是当前页码。
$.ajax({
url:"http://localhost/ecp/remote?callName=com.cloud.login.service.impl.CustomerAuthRS.queryAreaDetail()",
data:{
currentPage:currentPage,
pageSize: 10,
searchText:$("#contaKeyword").val(),//这个是选填的,如果用户没有输入就没有
},
dataType:'json',
type:"POST",
success:function(resdata,textStatus,jqXHResult){
if(resdata!=null&&resdata.data.length>0){
var vhtml='<tr> <th style="width:8%" class="center"></th> <th style="width:92%">学校名称</th></tr>';//z这里是那个头部的thz只有一个所以放在循环外部
for(var i=0;i<resdata.data.length;i++){
var orgCode=resdata.data[i].orgCode;
var orgName=resdata.data[i].orgName;
vhtml+='<tr><td><inputtype="radio"/></td><td>'+orgCode+'/'+orgName+'</td></tr>';
}
$("#contaUnselectTableList").append(vhtml);
//页码。后台传过来了总的页数
if(resdata.totalPage>1){
$("#resourcePagination").Pager(resdata.totalPage,{ //resdata.totalPage总页数必选参数
currentPageIndex: currentPage,//当前页索引,这个是调用函数时传过来的参数
currentPage: 1,
length: 3,
callback: function (pageIndex, currentPage, current){ //翻页调用此函数。
page(parseInt(pageIndex)); //翻页肯定是访问接口,把你点击的那个页码索引传过去。这里是在函数内访问他自己的外层函数
}
});
}
else{
$("#resourcePagination").empty();//页码小于等于o就不显示
}
}
else{
var ahtml='<tr><td></td><td>没有查询到内容</td></tr>';
$("#contaUnselectTableList").append(ahtml);
}
},
})
}
//刚进去页面就得触发一个函数显示所有数据
page(1)
// 搜索时执行上面函数,访问接口调数据
$("#contaBtnSearch").click(function(){
page(1);
})
//在输入框点击回车也触发搜素的按钮
$("#contaKeyword").keydown(function(e){
if(e.keyCode==13)
$("#contaBtnSearch").trigger("click");
})
</script>
</body>
</html>
接口回传的数据
html内容
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link href="js/jPaginate/pagination.css" rel="stylesheet"/>
</head>
<body>
<div class="search">
<input id="contaKeyword" type="text" placeholder="请输入机构或者学校名称进行搜索">
<input id="contaBtnSearch" type="button" value="Go">
</div>
<div class="conta_table_content">
<table border="0" cellspacing="0" cellpadding="0" class="conta_table_list" id="contaUnselectTableList">
<!-- 所有内容放在这里 -->
</table>
<div id="resourcePagination" class="pagination"></div> <!-- 分页效果 -->
</div>
<script src="js/jquery-3.1.1.min.js"></script>
<script src="js/jPaginate/jquery.paginate.js"></script>
<script>
//接口回传的数据:
//0 : {areaCode: "460205", cityCode: "460200", orgCode: "1146002201",…}
//1 : {areaCode: "460204", cityCode: "460200", orgCode: "2146000443",…}
//2 : {areaCode: "460204", cityCode: "460200", orgCode: "2146000297",…}
//3 : {areaCode: "460204", cityCode: "460200", orgCode: "3146000100",…}
//4 : {areaCode: "460205", cityCode: "460200", orgCode: "1146000083",…}
//5 : {areaCode: "460205", cityCode: "460200", orgCode: "1146002265",…}
//6 : {areaCode: "460205", cityCode: "460200", orgCode: "2146000340",…}
//7 : {areaCode: "460203", cityCode: "460200", orgCode: "3146000092",…}
//8 : {areaCode: "460202", cityCode: "460200", orgCode: "1146003246",…}
//9 : {areaCode: "460203", cityCode: "460200", orgCode: "1146001495",…}
//pageSize : 10
//totalPage : 32
//totalRecord : 311
function page(currentPage){ //currentPage是当前页码。
$.ajax({
url:"http://localhost/ecp/remote?callName=com.cloud.login.service.impl.CustomerAuthRS.queryAreaDetail()",
data:{
currentPage:currentPage,
pageSize: 10,
searchText:$("#contaKeyword").val(),//这个是选填的,如果用户没有输入就没有
},
dataType:'json',
type:"POST",
success:function(resdata,textStatus,jqXHResult){
if(resdata!=null&&resdata.data.length>0){
var vhtml='<tr> <th style="width:8%" class="center"></th> <th style="width:92%">学校名称</th></tr>';//z这里是那个头部的thz只有一个所以放在循环外部
for(var i=0;i<resdata.data.length;i++){
var orgCode=resdata.data[i].orgCode;
var orgName=resdata.data[i].orgName;
vhtml+='<tr><td><inputtype="radio"/></td><td>'+orgCode+'/'+orgName+'</td></tr>';
}
$("#contaUnselectTableList").append(vhtml);
//页码。后台传过来了总的页数
if(resdata.totalPage>1){
$("#resourcePagination").Pager(resdata.totalPage,{ //resdata.totalPage总页数必选参数
currentPageIndex: currentPage,//当前页索引,这个是调用函数时传过来的参数
currentPage: 1,
length: 3,
callback: function (pageIndex, currentPage, current){ //翻页调用此函数。
page(parseInt(pageIndex)); //翻页肯定是访问接口,把你点击的那个页码索引传过去。这里是在函数内访问他自己的外层函数
}
});
}
else{
$("#resourcePagination").empty();//页码小于等于o就不显示
}
}
else{
var ahtml='<tr><td></td><td>没有查询到内容</td></tr>';
$("#contaUnselectTableList").append(ahtml);
}
},
})
}
//刚进去页面就得触发一个函数显示所有数据
page(1)
// 搜索时执行上面函数,访问接口调数据
$("#contaBtnSearch").click(function(){
page(1);
})
//在输入框点击回车也触发搜素的按钮
$("#contaKeyword").keydown(function(e){
if(e.keyCode==13)
$("#contaBtnSearch").trigger("click");
})
</script>
</body>
</html>
相关文章推荐
- 带有分页排序功能的表格插件的使用(通过ajax获取后台数据)
- ajax获取json数据使用jquery分页插件显示
- jquery datatable 通过ajax从后台获取每个分页数据后,搜索框无法搜索问题
- 使用所见即所得文本编辑器编辑文本存入数据库后通过ajax获取服务器json_encode的数据到前台,文本内容上边的html标签不解析
- DataTables+BootStrap组合使用Ajax来获取数据并且动态加载dom的方法(排序,过滤,分页等)
- 通过AJAX获取ashx后台JSON数据并使用bootstrap-Table控件
- 豆瓣API使用介绍及通过ajax跨域获取url的json数据的方法
- Bootstrap 分页插件 ajax获取数据显示
- mui上拉加载通过ajax获取数据,实现分页
- Jquery 模板插件 jquery.tmpl.js 的使用方法(1):基本语法,绑定,each循环,ajax获取json数据
- Bootstrap 分页插件 ajax获取数据显示
- Jquery Easyui插件Datagrid获取后台mssql数据通过存储过程高效分页来获取
- jQuery插件select2利用ajax高效查询大数据列表(可搜索、可分页)
- jquery自动补全插件autocomplete的使用方法之autocomplete ajax获取数据展示
- ajax获取所有数据,前台分页,搜索
- 将jQuery Pagination分页插件用于不使用AJAX加载数据的页面
- Datatables插件1.10.15版本服务器处理模式ajax获取分页数据实例解析
- 关于使用jq的ajax通过josnp方式跨域获取数据
- 解决在 使用 AjaxFileUploder 插件时,不能获取返回的 json 结果数据
- 给ajax留一个模板,通过后台传递json获取数据,并用table显示,方便以后使用