+ -
当前位置:首页 → 问答吧 → php+ajax(prototype)简单类别级联+缓存

php+ajax(prototype)简单类别级联+缓存

时间:2009-01-18

来源:互联网


这是我做站时写的php+ajax类别级联+缓存,使用的是prototype-1.6.0.2,
这是无聊拿来共享一下,谈不上技术含量,呵呵
网站里的类别一般没什么变动,所以加了一个缓存。这样可以不用每次都去请求数据库。
如果网站类别有变动的话,可以在增加类别或删除修改类别的页面加一个更新缓存的代码即可。
[code]
<div id="BigType">
</div>
<div id="SmallType">
</div>

<script language="JavaScript" src="prototype-1.6.0.2.js"></script>
<script>
function GetBigType (){
       var url='GetBigType.php';
       var pars='pid=1';
       var myAjax=new Ajax.Updater('BigType', url, {method:'get', parameters:pars});
}
GetBigType ();
function GetSmallType(){
       var fatherid=$F('fatherid');
       var url=' GetSmallType.php';
       var pars='fatherid='+fatherid;
       var myAjax =new Ajax.Updater('SmallType', url, {method:'get', parameters:pars});
}
</script>

[/code]下面是GetBigType.php

<?php
header("Content-type: text/html;charset=GBK");//输出编码,避免中文乱码
require_once(dirname(__FILE__)."/include/config_base.php");
require_once(dirname(__FILE__)."/include/inc_type.php");
require_once(dirname(__FILE__)."/include/inc_cache.php");
$pid="";
$pid=$_GET['pid'];
if($pid==1){

if(!file_exists('../cache/bigtype.cache.txt')){


$ty = new Type(0);


$typeOptions = $ty->GetBigOption();


cache_write('/cache/bigtype.cache.txt', $typeOptions);


echo "<select name='fatherid' onChange='GetSmallType();' style='width:200;'>\r\n";


echo "<option value='0' selected>--不限栏目--</option>\r\n";


echo $typeOptions;


echo "</select>";


$ty->Close();

}else{


$typeOptions=cache_get('/cache/bigtype.cache.txt');


echo "<select name='fatherid' onChange='GetSmallType ();' style='width:200;'>\r\n";


echo "<option value='0' selected>--不限栏目--</option>\r\n";


echo $typeOptions;


echo "</select>";

}
}

?>


下面是GetSmallType.php


<?php
header("Content-type: text/html;charset=GBK");//输出编码,避免中文乱码
require_once(dirname(__FILE__)."/include/config_base.php");
require_once(dirname(__FILE__)."/include/inc_type.php");
require_once(dirname(__FILE__)."/include/inc_cache.php");

$fatherid="";
$fatherid=$_GET['fatherid'];

if(!empty($fatherid)){

if(!file_exists('/cache/sun_'.$fatherid.'_cache.txt')){

$ty = new Type(0);

$typeOptions = $ty->GetSmallOption($fatherid);

if(!empty($typeOptions)){

cache_write('/cache/sun_'.$fatherid.'_cache.txt', $typeOptions);

echo "<select name='sunid' style='width:200'>\r\n";

echo $typeOptions;

echo "</select>";

$tl->Close();

}

}else{

$typeOptions=cache_get('/cache/sun_'.$fatherid.'_cache.txt');

echo "<select name='sunid' style='width:200'>\r\n";

echo $typeOptions;

echo "</select>";

}
}
?>

作者: Scott.Lu   发布时间: 2009-01-18

看看

作者: cnkiller   发布时间: 2009-01-18

看看

作者: 网络疯子   发布时间: 2009-01-18

好东西都要看看

作者: entermaster   发布时间: 2009-01-18

好看一下

作者: mailangel123   发布时间: 2009-01-18

参考一下!

作者: anylzer   发布时间: 2009-01-18

想看下

作者: 星晴   发布时间: 2009-01-19

看看

作者: jun54555   发布时间: 2009-01-19

看一下,

作者: naodai   发布时间: 2009-01-19

好东西学习一下

作者: rky589   发布时间: 2009-01-19

看看

作者: artgou   发布时间: 2009-01-19

還是不太清楚ajax運作,希望能透過這個明白多一點><!
感謝樓主!

作者: ne3   发布时间: 2009-01-19

好看一下

作者: 一滴红尘泪   发布时间: 2009-01-19

不错的东西,看看

作者: 906mbc   发布时间: 2009-01-20

必须看下,

作者: libailin   发布时间: 2009-01-20

原帖由 naodai 于 2009-1-19 09:16 发表
看一下,

作者: fejay   发布时间: 2009-01-20

看看.................

作者: zjzgtony   发布时间: 2009-01-20

参考参考!支持一下

作者: fejay   发布时间: 2009-01-20

作者: lifeblood   发布时间: 2009-01-20

11111111111

作者: cjjc11   发布时间: 2009-01-21

参考一下

作者: niceup   发布时间: 2009-01-21

支持一下,谢谢楼主的分享

作者: xiejohnson   发布时间: 2009-01-21

看一下

作者: 67420   发布时间: 2009-01-23

我也来看看....

作者: pader   发布时间: 2009-01-23

好!
学习一下

作者: yyshenren   发布时间: 2009-01-27

顶!学习啦!

作者: yiguopan   发布时间: 2009-01-31

我也看看

作者: wuxp   发布时间: 2009-02-02

dsfdf

作者: zhangjianbo   发布时间: 2009-02-02

看看先...

作者: fileman   发布时间: 2009-02-02

1111111111

作者: 古嗣小井   发布时间: 2009-02-03

正在研究,看看

作者: nakaka   发布时间: 2009-02-03

还要 回复,什么人啊.

作者: 渔洋童话   发布时间: 2009-02-03

最好来点图片

作者: fejay   发布时间: 2009-02-03

学习下

作者: hjl   发布时间: 2009-02-04

缓存?这个需要研究一下

作者: 一贯而终   发布时间: 2009-02-04

顶了

作者: tetang1230   发布时间: 2009-02-04

我也来看看

作者: xxfs   发布时间: 2009-02-04

支持一下。。

作者: snang   发布时间: 2009-02-04

看看

作者: cnkiller   发布时间: 2009-02-04

var fatherid=$F('fatherid');
取不到值,我查官网才找到解决方法

作者: nakaka   发布时间: 2009-02-04

看看这呢想 提高 缓存 技术

作者: gavinzhu   发布时间: 2009-02-04