Ajax+smarty技术实现无刷新分页 - 网站

Ajax+smarty技术实现无刷新分页

分类:js_jQuery答疑 - 常见问题 · 发布时间:2021-10-07 12:04 · 阅读:2693

这篇文章主要介绍了Ajax+smarty技术实现无刷新分页的相关资料,需要的朋友可以参考下

这里运用Smarty模板,更简单

本文主要的技术:AJAX,PHP,Smarty,另外自己封装了一个很简单的类

类:

   (function(){ function $(id) { return document.getElementById(id); } $.init=function() { try{return new XMLHttpRequest();}catch(e){}; try{return new ActiveXObject('Microsoft.XMLHTTP');}catch(e){} alert('请更换浏览器'); } $.get=function (url,data,callback,type) { var xhr = this.init(); url += '?' +new Date().getTime(); if(data!=null){ url += '&'+data; } xhr.open('get',url); xhr.onreadystatechange = function () { if(xhr.readyState == 4 && xhr.status == 200){ if(type==null){ callback(xhr.responseText); } if(type == 'text'){ callback(xhr.responseText); } if(type == 'xml'){ callback(xhr.responseXML); } if(type == 'json'){ callback(eval("("+xhr.responseText+")")); } } } xhr.send(null); } $.post = function (url,data,callback,type) { var xhr = this.init(); xhr.open('post',url); xhr.setRequestHeader('Content-Type','Application/x-www-form-urlencoded'); xhr.onreadystatechange = function () { if(xhr.readyState == 4 && xhr.status == 200){ if(type==null){ callback(xhr.responseText); } if(type == 'text'){ callback(xhr.responseText); } if(type == 'xml'){ callback(xhr.responseXML); } if(type == 'json'){ callback(eval("("+xhr.responseText+")")); } } }; xhr.send(data); }

 类很简单,不介绍了

HTML:

   window.onload=function () { init(2); } function del(id,p){ $.get('del.php','id='+id,function(msg){ if(msg==1){ init(p); } }) } function init(p) { $.get('page.php','page='+p,function(msg){ $('result').innerHTML=msg; }); } PHP: $total){$next=$total;} $offset = ($page-1)*$pagesize; $result=mysql_query("select * from catgory limit ".$offset.','.$pagesize); $ct=mysql_num_rows($result); $data=array(); for($i=0;$i<$ct;$i++){ $r=mysql_fetch_assoc($result); $data[]=$r; } include('libs/Smarty.class.php'); $Smarty=new Smarty(); $Smarty->assign('data',$data); $Smarty->assign('page',$page); $Smarty->assign('pagesize',$pagesize); $Smarty->assign('total',$total); $Smarty->assign('prev',$prev); $Smarty->assign('next',$next); $Smarty->assign('row1',$row1); $str=$Smarty->fetch('page.html'); echo $str;

Smarty:

      {foreach from=$data item='value'}  {/foreach} 
编号品牌pid删除
{$value['id']}{$value['name']}{$value['pid']}删除
共{$total}页 第{$page}页 上一页下一页第一页最末页 共{$row1}条数据 每页{$pagesize}条数据

要引入smary模板

以上所述是小编给大家介绍的Ajax+smarty技术实现无刷新分页,希望对大家有所帮助!

标签:
smarty 分页 不刷新

相关文章

AJAX乱码与异步同步以及封装jQuery库实现步骤详解

这篇文章主要介绍了异步通信技术AJAX乱码问题、异步与同步、手动封装一个jQuery库,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习吧

AJAX的跨域问题解决方案

跨域简单的说,就是从一个域名的网页去访问另一个域名网页的资源,下面这篇文章主要给大家介绍了关于AJAX的跨域问题解决的相关资料,文中通过实例代码介绍的非常详细,需要的朋友可以参考下

利用Ajax实现智能回答的机器人示例代码

这篇文章主要介绍了利用Ajax实现智能回答的机器人,本文结合示例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

ajax、axios和fetch之间优缺点重点对比总结

今天被问到用没用过ajax axios,我回答经常用axios,但ajax用的比较少,下面这篇文章主要给大家介绍了关于ajax、axios和fetch之间优缺点重点对比总结的相关资料,需要的朋友可以参考下

如何通过axios发起Ajax请求(最新推荐)

Axios是专注于网络数据请求的库,相比于原生的XMLHttpRequest对象,axios简单易用。相比于Jquery,axios更加轻量化,只专注于网络数据请求,这篇文章主要介绍了如何通过axios发起Ajax请求,需要的朋友可以参考下

返回分类 返回首页