AJAX分頁效果簡單實(shí)現(xiàn)
最近寫一個(gè)給用戶組添加角色的功能,要求一邊是未添加的角色,一邊是已添加的角色,還有搜索功能, 點(diǎn)擊添加后,ajax保存操作.
考慮功能為待查詢功能分頁 , 下方分頁條, 一共有 2*2 ,4個(gè)ajax…

JS代碼如下:
$(document).ready(function() {
App.init();
currentRole(); // 當(dāng)前角色
currentRolePage();//當(dāng)前角色分頁
noAddRole(); //未添加角色
noAddRolePage();//未添加角色分頁
});
//當(dāng)前角色列表
function currentRole(){
var currentRoleCheckName =$("#currentRoleCheckName").val();
// 當(dāng)前角色的list集合
$.ajax({
async:true,
type:"POST",
//date:"groupId=rose",//發(fā)送到服務(wù)器的數(shù)據(jù)
url:"${ctx}/group/ajax_showRolesForGroup.do",//請求路徑
data:{"groupId":groupId,
"page":page1,
"checkName":currentRoleCheckName
},
dataType:"json", //返回?cái)?shù)據(jù)的類型
success:function(data){ //成功響應(yīng)后的回調(diào)函數(shù)
var result =data.pageSupport.items;
console.log(data.pageSupport)
var s="";
for(var i in result){
s+="<tr class='odd gradeX'><td>"+result[i].name+"</td>"
+"<td>"+result[i].remark+"</td>"
+"<td><button type='button' class='btn btn-xs btn-info m-r-5' onclick='to_RemoveRoleToGroup("+result[i].roleId+");'>移除</button></td></tr>";
}
$("#currentRole").html(s);
}
});
}
//當(dāng)前角色的分頁
function currentRolePage(){
var currentRoleCheckName =$("#currentRoleCheckName").val();
var totalPage=0;
$.ajax({
async:true,
type:"POST",
//date:"groupId=rose",//發(fā)送到服務(wù)器的數(shù)據(jù)
url:"${ctx}/group/ajax_showRolesForGroup.do",//請求路徑
data:{"groupId":groupId,
"page":page1,
"checkName":currentRoleCheckName
},
dataType:"json", //返回?cái)?shù)據(jù)的類型
success:function(data){ //成功響應(yīng)后的回調(diào)函數(shù)
totalPage=data.pageSupport.last;
console.log(totalPage)
var i= 0;
var a="";
for( i=page1-2; i<=page1+2;i++){
if(i>0 && i<=totalPage){
if(i == 1){
$("#prev1").attr('class','disabled');
}
if(page1 == i){
a+="<li class='active' bs1='" + i + "'><a>"+i+"</a></li>";
}else{
a+="<li class='zhong1' bs1='" + i + "'><a href='javascript:void(0);' onclick='a_method("+i+");' >"+i+"</a></li>";
}
}
}
$("#fy_list").html(a);
}
});
}
//中間頁
function a_method(i) {
page1 = i;
currentRole(); // 當(dāng)前角色
currentRolePage();//當(dāng)前角色分頁
}
//查詢操作
function currentRoleCheck(){
page1=1;
currentRole(); // 當(dāng)前角色
currentRolePage();//當(dāng)前角色分頁
}
HTML代碼如下:
<!-- 兩個(gè)相同的DIV 下面只是一個(gè)-->
<div class="panel-body col-md-6">
<div style="border: 1px solid #E0E0E0;border-radius: 4px">
<div class="panel-heading " style="background-color:#E0E0E0; ">
<h2 class="panel-title"><b>已選角色</b></h2>
</div>
<div id="firstCheck" class="panel-body">
<div style="padding-left: 0 !important;" id="firstCheck" class="panel-body">
<form class="form-inline" method="POST" >
<div class="form-group m-r-10">
<input id="currentRoleCheckName" type="text" class="form-control" placeholder="角色名稱" name="fname" maxlength="40" />
</div>
<div class="checkbox m-r-10">
</div>
<button id="currentCheck"type="button" class="btn btn-sm btn-primary m-r-5" onclick="currentRoleCheck()" >查詢</button>
</form>
</div>
<div >
<table id='data-table' class='table table-bordered' >
<thead>
<tr>
<th>角色名稱</th>
<th>備注信息</th>
<th>操作</th>
</tr>
</thead>
<tbody id="currentRole">
<!--
當(dāng)前用戶組已有角色list
-->
</tbody>
</table>
</div>
<div class="buttonBox">
<div align="right">
<ul id="fy_list" class="pagination pagination-sm m-t-0 m-b-10 ">
</ul>
</div>
</div>
</div>
</div>
</div>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 用jQuery中的ajax分頁實(shí)現(xiàn)代碼
- JQuery+Ajax無刷新分頁的實(shí)例代碼
- jQuery Pagination Ajax分頁插件(分頁切換時(shí)無刷新與延遲)中文翻譯版
- Ajax讀取數(shù)據(jù)之分頁顯示篇實(shí)現(xiàn)代碼
- php,ajax實(shí)現(xiàn)分頁
- JS+Ajax+Jquery實(shí)現(xiàn)頁面無刷新分頁以及分組 超強(qiáng)的實(shí)現(xiàn)
- jQuery DataTables插件自定義Ajax分頁實(shí)例解析
- 使用PHP+JQuery+Ajax分頁的實(shí)現(xiàn)
- php+ajax實(shí)現(xiàn)無刷新分頁的方法
- 基于Jquery+Ajax+Json的高效分頁實(shí)現(xiàn)代碼
相關(guān)文章
基于Ajax和forms組件實(shí)現(xiàn)注冊功能的實(shí)例代碼
本文通過實(shí)例代碼給大家分享了基于Ajax和forms組件實(shí)現(xiàn)注冊功能,需要的朋友可以參考下2018-02-02
ajax實(shí)現(xiàn)的提交文章前進(jìn)行敏感詞審核的代碼
在做“文章敏感詞匯審核”功能的時(shí)候,開始在把“審核”放在插入數(shù)據(jù)庫的時(shí)候,后來想有一個(gè)功能,能在用戶點(diǎn)擊“提交”按鈕的時(shí)候,給一個(gè)提示。這樣相對“友好”那么點(diǎn)。2010-02-02
springmvc 發(fā)送ajax出現(xiàn)中文亂碼的解決方法匯總
本文給大家介紹四種方法解決springmvc 發(fā)送ajax出現(xiàn)中文亂碼問題,非常具有參考借鑒價(jià)值,感興趣的朋友一起學(xué)習(xí)吧2016-03-03
菜鳥蔡之Ajax復(fù)習(xí)第三篇(Ajax之無刷新登錄)
無刷新登錄大家也許沒寫過,但是一定都是聽說過的,很早以前就想用這個(gè)小技術(shù)在自己做的小項(xiàng)目中用一把了,但都沒有付出過實(shí)踐,在網(wǎng)上查也沒有查到具體完整的代碼,在這里,今天菜鳥蔡也來試了一把,獻(xiàn)丑了,希望對初學(xué)的童鞋有點(diǎn)幫助2012-11-11
JS AJAX前臺(tái)如何給后臺(tái)類的函數(shù)傳遞參數(shù)
這篇文章主要介紹了JS AJAX前臺(tái)給后臺(tái)類的函數(shù)傳遞參數(shù)的方法,下面有個(gè)不錯(cuò)的示例,需要的朋友可以參考下2014-06-06
ajax動(dòng)態(tài)查詢數(shù)據(jù)庫數(shù)據(jù)并顯示在前臺(tái)的方法
今天小編就為大家分享一篇ajax動(dòng)態(tài)查詢數(shù)據(jù)庫數(shù)據(jù)并顯示在前臺(tái)的方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08

