复制代码 代码如下: js 端 及判断 <br>$(function(){ <br>//var url=$(this)[0].location.href; <br>//alert(url); <br>goPageFirst(); <br>$('#selpage').bind('change',goPage); <br>}); <br>//返回当前页数 <br>function getNowPage() <br>{ <br>return parseInt($('#nowPage').html()); <br>} <br>//返回每页显示的条数 <br>function getPer() <br>{ <br>return $('#perPage').val(); <br>} <br>//返回总记录数 <br>function getTotal() <br>{ <br>return parseInt($('#total').html()); <br>} <br>//返回总页数 <br>function getAllPage() <br>{ <br>return parseInt($('#allpage').html()); <br>} <br>//组合字符串参数 <br>function getData(act) <br>{ <br>var target=1; <br>var now=getNowPage()+1; <br>var per=getPer(); <br>var sum=getTotal(); <br>var allpage=getAllPage(); <br>switch(act) <br>{ <br>case 'first': <br>target=1; <br>break; <br>case 'prev': <br>target=now>1?now-1:1; <br>break; <br>case 'next': <br>target=now+1>allpage?now:1; <br>break; <br>case 'last': <br>target=allpage>0?allpage:1; <br>break; <br>case 'constans': <br>target=$('#selpage').val()>0?$('#selpage').val():1; <br>default : <br>target=1; <br>} <br>var data="check="+act+"&nowpage="+now+"&perpage="+per+'&target='+target; <br>alert(data); <br>return data; <br>} <br>//执行第一页 <br>function goPageFirst() <br>{ <br>var param=getData('first'); <br>http_post(param); <br>} <br>//执行上一页 <br>function goPagePrev() <br>{ <br>var param=getData('prev'); <br>http_post(param); <br>} <br>//执行下一页 <br>function goPageNext() <br>{ <br>var param=getData('next'); <br>http_post(param); <br>} <br>//执行最后页 <br>function goPageLast() <br>{ <br>var param=getData('last'); <br>http_post(param); <br>} <br>//选中到指定页面 <br>function goPage() <br>{ <br>var param=getData('constans'); <br>http_post(param); <br>} <br>//post 请求数据加载 <br>function http_post(db) <br>{ <br>$.post('./mysql.php',db,function(data){ <br>responseAjax(data); <br>},'text'); <br>} <br>//返回数据的调处理 <br>function responseAjax(msg) <br>{ <br>//alert(msg); <br>//alert(msg.content); <br>//$('#listDiv').html(msg.content); <br>$('#listDiv').html(msg); <br>} <br>server端 判断及实现 <br>//@autor 499188204@qq.com <br>mb_internal_encoding('gb2312'); <br>$con=mysql_connect("127.0.0.1","root","12345678") or die("连接失败"); <br>$m=mysql_select_db("ec",$con); <br>$sql = 'SELECT `attr_id`,`cat_id`,`attr_name` <br>FROM `ecs_attribute` '; <br>$rs = mysql_query($sql ); <br>$count = mysql_num_rows($rs); //返回记录总数 <br>//echo $count; //总记录数 <br>//每页的记录数 10 <br>//求总页数 ceil($count/10) <br>//echo '<hr >'; <br>if(!isset($_POST['check'])) <br>{ <br>$set['id']=0; <br>die('no access please!'); <br>} <br>if(isset($_POST['perpage']) && $_POST['perpage']>0 ) <br>{ <br>$per=$_POST['perpage']; <br>} <br>else <br>{ <br>$per=15; <br>} <br>$page = ceil($count/$per); <br>//echo $page; <br>if(!isset($_POST['nowpage'])) <br>{ <br>$nowPage=1; <br>} <br>else <br>{ <br>$nowPage = $_POST['nowpage']; <br>} <br>$start = ($nowPage-1)*$per+1; <br>$sql = 'select `attr_id`,`cat_id`,`attr_name` from `ecs_attribute` limit '.$start.','. $per; <br>//$sql = 'select `attr_id`,`cat_id`,`attr_name` from `ecs_attribute` limit 10 offset 20'; <br>$rs = mysql_query($sql ); <br>$str = "<table> <br><tr><th>属性编号</th><th>类型编号</th><th>属性名字</th></tr>"; <br>while($row = mysql_fetch_assoc($rs)){ <br>$str .='<tr><td>'.$row['attr_id'].'</td><td>'.$row['cat_id'].'</td><td>'.$row['attr_name'].'</td><tr>'; <br>} <br>$str.="</table> <br><table> <br><tr><td><div><span>总计<span>".$count."</span>个记录分为<span>".$page."</span>页当前第<span>".$nowPage."</span>页,每页<input type='text' value='".$per."'/> | <br><a >"; <br>for($i=1;$i <=$page;$i++) <BR>{ <BR>if($nowPage==$i) <BR>{ <BR>$str .= "<option selected >".$i."</option>"; <br>} <br>else <br>{ <br>$str .= "<option >".$i."</option>"; <br>} <br>} <br>$str .="</select> <br></span></div> <br>"; <br>echo mb_convert_encoding($str,'UTF-8','gb2312'); <br>//$set['content']=$str; <br>/ /echo json_encode($set); <br>?> <br></p> <p> 以上就介紹了asp.net ajax php ajax 靜態分頁過程形式,包括了asp.net ajax方面的內容,希望對PHP教程有興趣的朋友有所幫助。 </p> <p> </p>