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
感謝樓主!
作者: ne3 发布时间: 2009-01-19
作者: 一滴红尘泪 发布时间: 2009-01-19
作者: 906mbc 发布时间: 2009-01-20
作者: libailin 发布时间: 2009-01-20
看一下,
作者: fejay 发布时间: 2009-01-20
作者: zjzgtony 发布时间: 2009-01-20
作者: fejay 发布时间: 2009-01-20



作者: lifeblood 发布时间: 2009-01-20
作者: 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
作者: zhangjianbo 发布时间: 2009-02-02
作者: fileman 发布时间: 2009-02-02
作者: 古嗣小井 发布时间: 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
取不到值,我查官网才找到解决方法
作者: nakaka 发布时间: 2009-02-04
作者: gavinzhu 发布时间: 2009-02-04
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28