jQuery+Ajax+PHP+Mysql实现分页显示数据

html:
<table>

      <thead>

           <tr>

                <th class="node">公司名称</th>

                <th class="node">公司类型</th>

                <th class="name">营业资格证</th>

                <th class="name">安全许可证号</th>

                <th class="name">组织机构代码</th>

                <th class="name">审核状态</th>

                <th class="operate">操作</th>

           </tr>

      </thead>

      <tbody id="rowTempLate">

      </tbody>

</table>

js代码

<script type="text/javascript">

var pageIndex =0;

var pagesize = 10;

function getDataList(index,size){

var iDisplayStart = size*index;

index +=1;

$.ajax({

url:"<?PHP echo "/".$url_module."/".$url_model?>/page",

type:"post",

data:{

sEcho:index,

iDisplayLength:size,

iDisplayStart:iDisplayStart,

token:'<?php echo isset($token)?$token:"";?>'

},

success:function(res){

var r =$.parseJSON(res);

if(r !=null&&r.ret==0){

$("#rowTemplate tr").remove();

var myc =0;

$.each(r.aaData,function(i,t){

myc +=1;

var mytr ="<tr>";

if(myc%2 ==0){

mytr ="<tr style='background-color:rgb(239,246,250);'>";

}

$("#rowTemplate").append(mytr +"<td class='node'>" + t.companyname +"</td>"+"<td class='name'>" + t.companytypename +"</td>""+<td class='name'>" + t.businesslicensecode +"</td>"+"<td class='name'>" + t.safetylicensecode +"</td>"+"<td class='name'>" + t.organizationcode +"</td>"+"<td class='name'>" + t.status +"</td>"+"<td class='operate'><a href=\"<?php echo "/".$url_module."/".$url_method;?>/edit/" +t.id +"\">编辑</a>"+"<a href=\"<?php echo "/".$url_module."/".$url_method;?>/view/" +t.id +"\">明细</a>"+"</td></tr>");

});

$(".pagination").pagination(r.iTotalRecords,{

callback:PageCallback,

items_per_page:size,

display_msg:true,

setPageNo:true,

current_page:index-1

})

}

else{

alert(r.msg);

}

}

})

}

 

php代码

public function _getListSql(){

$sql="SELECT*FROM".$this->mydb->getTable();

return $sql;

}

public function page(){

$sessionKey='Search_'.$this->url_module.'_'.$this->url_model;

$arrSearch=$this->session->userdate($sessionKey);

$sql=$this->_getListSql();

$sql=$this->_addWhere($sql,$arrSearch);

$griddefine=$this->griddefine;

$aColums = array($griddefine['keyid']);

foreach($griddefine['listfield'] as $arrTmp)

array_push($aColums,$arrTmp["fieldname"]);

$data=$this->mydb->pagingServer($aColumns,$sql);

echo json_encode($this->_beforeMethod($data['obj']));

}

posted on 2015-07-10 16:20  勤奋者努力着  阅读(342)  评论(0编辑  收藏  举报

导航