欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

實(shí)例代碼講解ajax實(shí)現(xiàn)的無(wú)刷新分頁(yè)

 更新時(shí)間:2015年12月26日 09:32:08   作者:程序員小菜  
這篇文章主要介紹了實(shí)例代碼講解ajax實(shí)現(xiàn)的無(wú)刷新分頁(yè)的相關(guān)資料,需要的朋友可以參考下

1、Ajax 無(wú)刷新頁(yè)面的好處:提供良好的客戶體驗(yàn),通過 Ajax 在后臺(tái)從數(shù)據(jù)庫(kù)中取得數(shù)據(jù)并展示,取締了等待加載頁(yè)面而出現(xiàn)的空白狀態(tài);

2、那么,Ajax 無(wú)刷新頁(yè)面是運(yùn)行在動(dòng)態(tài)頁(yè)面(.php)?還是靜態(tài)頁(yè)面(.html/.htm/.shtml)?答案是:靜態(tài)頁(yè)面;

3、實(shí)現(xiàn)原理:通過前端 JS 腳本程序與 Ajax 相結(jié)合取得從動(dòng)態(tài)頁(yè)面返回的數(shù)據(jù),并顯示。

現(xiàn)在什么都講究一個(gè)無(wú)刷新,就連分頁(yè)也是如此,下面是小編日常整理的關(guān)于一段無(wú)刷新代碼,希望能夠幫到大家。

代碼如下:

一.html代碼部分:

<table class="table style-5"> 
 <thead id="t_head"> 
  <tr> 
   <th>序號(hào)</th> 
   <th>標(biāo)題</th> 
   <th>地點(diǎn)</th> 
   <th>已報(bào)名</th> 
   <th>類別</th> 
   <th>操作</th> 
  </tr> 
</thead> 
<tbody id="t_body"> 
<!-- ajax填充列表 -->
</tbody> 
</table> 
<button id="firstPage">首頁(yè)</button> 
<button id="previous">上一頁(yè)</button> 
<button id="next">下一頁(yè)</button> 
<button id="last">尾頁(yè)</button> 

二.ajax代碼部分:

var pageSize = "10";//每頁(yè)行數(shù) 
var currentPage = "1";//當(dāng)前頁(yè) 
var totalPage = "0";//總頁(yè)數(shù) 
var rowCount = "0";//總條數(shù) 
var params="";//參數(shù) 
var url="activity_list.action";//action 
$(document).ready(function(){//jquery代碼隨著document加載完畢而加載 
 //分頁(yè)查詢 
 function queryForPages()
 { 
  $.ajax({ 
   url:url, 
   type:'post', 
   dataType:'json', 
   data:"qo.currentPage="+currentPage+"&qo.pageSize="+pageSize+params, 
   success:function callbackFun(data)
   { 
    //解析json 
    var info = eval("("+data+")"); 
    //清空數(shù)據(jù) 
    clearDate(); 
    fillTable(info); 
   } 
  }); 
 } 
 //填充數(shù)據(jù) 
 function fillTable(info)
 { 
  if(info.length>1)
  { 
   totalPage=info[info.length-1].totalPage; 
   var tbody_content="";//不初始化字符串"",會(huì)默認(rèn)"undefined" 
   for(var i=0;i<info.length-1;i++)
   { 
    tbody_content +="<tr>" 
    +"<td data-title='序號(hào)' >"+(i+1+(currentPage-1)*pageSize)+"</td>" 
    +"<td data-title='標(biāo)題'>"+info[i].title.substr(0,20)+"</td>" 
    +"<td data-title='地點(diǎn)'>"+info[i].address.substr(0,6)+"</td>" 
    +"<td data-title='已報(bào)名'>"+info[i].quota_sign+"人</td>" 
    +"<td data-title='類別'>"+info[i].type+"</td>" 
    +"<td data-title='操作'><a href='<%=request.getContextPath()%>/activity_edit.action?id="+info[i].id+"'>編輯</a></td>" 
    +"</tr>" 
    $("#t_body").html(tbody_content); 
   } 
  }
  else
  { 
   $("#t_head").html(""); 
   $("#t_body").html("<div style='height: 200px;width: 700px;padding-top: 100px;' align='center'>"+info.msg+"</div>"); 
  } 
 } 
 //清空數(shù)據(jù) 
 function clearDate()
 { 
  $("#t_body").html(""); 
 }
 //搜索活動(dòng) 
 $("#searchActivity").click(function(){ 
  queryForPages();
 }); 
 //首頁(yè) 
 $("#firstPage").click(function(){ 
  currentPage="1"; 
  queryForPages(); 
 }); 
 //上一頁(yè) 
 $("#previous").click(function(){ 
  if(currentPage>1)
  { 
   currentPage-- ; 
  } 
  queryForPages(); 
 }); 
 //下一頁(yè) 
 $("#next").click(function(){ 
  if(currentPage<totalPage)
  { 
   currentPage++ ; 
  } 
  queryForPages(); 
 }); 
 //尾頁(yè) 
 $("#last").click(function(){ 
  currentPage = totalPage; 
  queryForPages(); 
 }); 
});

以上代碼是小編給大家介紹的ajax實(shí)現(xiàn)的無(wú)刷新分頁(yè),希望對(duì)大家有所幫助。

相關(guān)文章

最新評(píng)論