基于asp+ajax和数据库驱动的二级联动菜单
2015-01-24信息快讯网
基于asp+ajax和数据库驱动的二级联动菜单,需要的朋友可以参考下。
index.asp 页面代码
<!--#include file="conn.asp" -->
<%
set cmd = conn.execute("select bigclassid,bigclassname from bigclass")
tempid=cmd("bigclassid")
%>
<select name="menu" onChange="getsubcategory(this.value);">
<%
if not cmd.eof then
do while not cmd.eof
bigclassid= cmd("bigclassid")
bigclassname = cmd("bigclassname")
%>
<option value="<%=bigclassid%>"><%=bigclassname%></option>
<%
cmd.movenext
loop
end if
cmd.close
set cmd = nothing
%>
</select>
<div id="subclass">
<select name="submenu">
<%
set cxd = conn.execute("select * from smallclass where bigclassid=" & tempid)
if not cxd.eof then
do while not cxd.eof
smallclassid= cxd("smallclassid")
smallclassname = cxd("smallclassname")%>
<option value="<%=smallclassid%>"><%=smallclassname%></option>
<%
cxd.movenext
loop
cxd.close
set cxd = nothing
else
html = "<select name='smallclassid'><option value='0' selected>暂无小类</option></select>"
response.write html
end if
%>
</select>
</div>
ajax.js 代码
// JavaScript Document
function createxmlhttp()
{
xmlhttpobj = false;
try{
xmlhttpobj = new XMLHttpRequest;
}catch(e){
try{
xmlhttpobj=new ActiveXObject("MSXML2.XMLHTTP");
}catch(e2){
try{
xmlhttpobj=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e3){
xmlhttpobj = false;
}
}
}
return xmlhttpobj;
}
function getsubcategory(bigclassid){
if(bigclassid==0){
document.getElementById("subclass").innerHTML="<select name='smallclassid'><option value='0' selected>选择二级分类</option></select>";
return;
};
var xmlhttpobj = createxmlhttp();
if(xmlhttpobj){//如果创建对象xmlhttpobj成功
xmlhttpobj.onreadystatechange=handle;
xmlhttpobj.open('get',"getsubcategory.asp?bigclassid="+bigclassid+"&number="+Math.random(),true);//get方法 加个随机数。
xmlhttpobj.send(null);
}
}
function handle(){//客户端监控函数
//if(xmlhttpobj.readystate==4){//服务器处理请求完成
if(xmlhttpobj.status==200){
//alert('ok');
var html = xmlhttpobj.responseText;//获得返回值
document.getElementById("subclass").innerHTML=html;
}else{
document.getElementById("subclass").innerHTML="对不起,您请求的页面有问题...";
}
//}
//else{
//document.getElementById("subclass").innerHTML=xmlhttpobj.readystate;//服务器处理中
//}
//}
}
getsubcategory.asp 代码
<%@language="vbscript" codepage="936"%>
<!--#include file="conn.asp"-->
<%
response.charset="gb2312"
bigclassid=safe(request.querystring("bigclassid"))
if bigclassid<>"" then
set re=new regexp
re.ignorecase=true
re.global=false
re.pattern = "^[0-9]{1,3}$"
if not re.test(bigclassid) then
response.write "非法参数"
response.end
end if%>
<%on error resume next
set p = conn.execute("select * from smallclass where bigclassid=" & bigclassid)
if err then
err.clear
response.write "查询出错"
response.end
end if
if not p.eof then
html = "<select name='select2'>"&vbnewline
do while not p.eof
html = html&"<option value='"&p("smallclassid")&"'>"&p("smallclassname")&"</option>"&vbnewline
p.movenext
loop
html = html&"</select>"
else
html = "<select name='smallclassid'><option value='0' selected>暂无小类</option></select>"
end if
p.close
set p = nothing
conn.close
set conn = nothing
response.write html
html = ""
end if
%>
PHP 命令行工具 shell_exec, exec, passthru, system详细使用介绍
php 广告调用类代码(支持Flash调用)
PHP中用hash实现的数组
php设计模式 Chain Of Responsibility (职责链模式)
php smarty 二级分类代码和模版循环例子
sphinx增量索引的一个问题
PHP5中新增stdClass 内部保留类
PHP中遍历stdclass object的实现代码
php smarty 二级分类代码和模版循环例子
php异常:Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE eval()'d code error
PHP sprintf()函数用例解析
PHP中调用ASP.NET的WebService的代码
php模拟asp中的XmlHttpRequest实现http请求的代码
破解图片防盗链的代码(asp/php)测试通过
PHP,ASP.JAVA,JAVA代码格式化工具整理
php源码加密 仿微盾PHP加密专家(PHPCodeLock)
PHP 类商品秒杀计时实现代码
asp.net Repeater控件的说明及详细介绍及使用方法
使用PHP提取视频网站页面中的FLASH地址的代码
php读取javascript设置的cookies的代码
DedeCMS 核心类TypeLink.class.php摘要笔记
用php或asp创建网页桌面快捷方式的代码
php htmlspecialchars加强版
Asp.net 文本框全选的实现
php download.php实现代码 跳转到下载文件(response.redirect)
AspNetAjaxPager,Asp.Net通用无刷新Ajax分页控件,支持多样式多数据绑定
用php+javascript实现二级级联菜单的制作