這篇文章主要為大家展示了“AJAX分頁效果的實現(xiàn)方法”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“AJAX分頁效果的實現(xiàn)方法”這篇文章吧。

最近寫一個給用戶組添加角色的功能,要求一邊是未添加的角色,一邊是已添加的角色,還有搜索功能, 點擊添加后,ajax保存操作.
考慮功能為待查詢功能分頁 , 下方分頁條, 一共有 2*2 ,4個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", //返回數(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", //返回數(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代碼如下:
<!-- 兩個相同的DIV 下面只是一個--> <div class="panel-body col-md-6"> <div > <div class="panel-heading " > <h3 class="panel-title"><b>已選角色</b></h3> </div> <div id="firstCheck" class="panel-body"> <div 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>
以上是“AJAX分頁效果的實現(xiàn)方法”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
標(biāo)題名稱:AJAX分頁效果的實現(xiàn)方法-創(chuàng)新互聯(lián)
鏈接URL:http://www.yijiale78.com/article36/ddcssg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)、軟件開發(fā)、營銷型網(wǎng)站建設(shè)、標(biāo)簽優(yōu)化、ChatGPT、網(wǎng)站策劃
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容