濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > Ajax+smarty技術(shù)實(shí)現(xiàn)無(wú)刷新分頁(yè)

Ajax+smarty技術(shù)實(shí)現(xiàn)無(wú)刷新分頁(yè)

熱門(mén)標(biāo)簽:硅語(yǔ)電話機(jī)器人公司 騰訊地圖標(biāo)注位置能用多久 機(jī)器人電銷(xiāo)騙局揭秘 越南河內(nèi)地圖標(biāo)注 個(gè)人怎樣在百度地圖標(biāo)注地名 ai機(jī)器人電銷(xiāo)資源 云呼外撥網(wǎng)絡(luò)電話系統(tǒng) 超級(jí)大富翁地圖標(biāo)注 地圖標(biāo)注項(xiàng)目怎么樣

這里運(yùn)用Smarty模板,更簡(jiǎn)單

本文主要的技術(shù):AJAX,PHP,Smarty,另外自己封裝了一個(gè)很簡(jiǎn)單的類

類:

  (function(){
function $(id) {
return document.getElementById(id);
}
$.init=function() {
try{return new XMLHttpRequest();}catch(e){};
try{return new ActiveXObject('Microsoft.XMLHTTP');}catch(e){}
alert('請(qǐng)更換瀏覽器');
}
$.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);
}

 類很簡(jiǎn)單,不介紹了

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:

?php
header('content-type:text/html;charset=utf-8');
mysql_connect('localhost','root','root');
mysql_select_db('db2');
mysql_query('set names utf8');
$re=mysql_query('select count(*) as num from catgory');
$hang=mysql_fetch_assoc($re);
$row1=$hang['num'];
$page=isset($_GET['page'])? $_GET['page']:1;
$pagesize=2;
$total=ceil($row1/$pagesize);
$prev=$page-1;
$next=$page+1;
if($prev1){$prev=1;}
if($next>$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:

    table border="1" rules="all" width="600">
tr>
td>編號(hào)/td>
td>品牌/td>
td>pid/td>
td>刪除/td>
/tr>
{foreach from=$data item='value'}
tr>
td>{$value['id']}/td>
td>{$value['name']}/td>
td>{$value['pid']}/td>
td>a href="#", onclick="del({$value['id']},{$page})">刪除/td>
/tr>
{/foreach}
tr>
td colspan="3">
共{$total}頁(yè)
第{$page}頁(yè)
a href="#", onclick="init({$prev})">上一頁(yè)/a>
a href="#", onclick="init({$next})">下一頁(yè)/a>
a href="#", onclick="init(1)">第一頁(yè)/a>
a href="#", onclick="init({$total})">最末頁(yè)/a>
共{$row1}條數(shù)據(jù)
每頁(yè){$pagesize}條數(shù)據(jù)
/td>
/tr>
/table>

要引入smary模板

以上所述是小編給大家介紹的Ajax+smarty技術(shù)實(shí)現(xiàn)無(wú)刷新分頁(yè),希望對(duì)大家有所幫助!

您可能感興趣的文章:
  • smarty簡(jiǎn)單分頁(yè)的實(shí)現(xiàn)方法
  • Smarty變量用法詳解
  • Smarty環(huán)境配置與使用入門(mén)教程
  • PHP Smarty模版簡(jiǎn)單使用方法
  • Smarty安裝配置方法
  • 在smarty中調(diào)用php內(nèi)置函數(shù)的方法
  • ThinkPHP使用smarty模板引擎的方法
  • Smarty結(jié)合Ajax實(shí)現(xiàn)無(wú)刷新留言本實(shí)例
  • Smarty分頁(yè)實(shí)現(xiàn)方法完整實(shí)例

標(biāo)簽:遼源 海南 林芝 邢臺(tái) 內(nèi)蒙古 舟山 鄭州 洛陽(yáng)

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Ajax+smarty技術(shù)實(shí)現(xiàn)無(wú)刷新分頁(yè)》,本文關(guān)鍵詞  Ajax+smarty,技術(shù),實(shí)現(xiàn),無(wú),;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Ajax+smarty技術(shù)實(shí)現(xiàn)無(wú)刷新分頁(yè)》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于Ajax+smarty技術(shù)實(shí)現(xiàn)無(wú)刷新分頁(yè)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    中牟县| 石阡县| 新乡市| 台南县| 建阳市| 武清区| 汾阳市| 灵山县| 抚州市| 工布江达县| 甘南县| 虞城县| 齐齐哈尔市| 奈曼旗| 湖口县| 沅江市| 视频| 裕民县| 稷山县| 碌曲县| 连城县| 高阳县| 凌源市| 庐江县| 宝清县| 彰化市| 祁连县| 谷城县| 和田县| 康保县| 禄丰县| 沧州市| 尖扎县| 峨眉山市| 高安市| 玛纳斯县| 麟游县| 循化| 翁牛特旗| 华阴市| 平乡县|