• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

基于asp+ajax和数据库驱动的二级联动菜单_php技巧

php 搞代码 4年前 (2022-01-26) 12次浏览 已收录 0个评论

index.asp 页面代码

 <BR><!---ecms -ecms #include file="conn.asp" --> <BR><% <BR>set cmd = conn.execute("select bigclassid,bigclassname from bigclass") <BR>tempid=cmd("bigclassid") <BR>%> <BR> <br><br><% <BR>if not cmd.eof then <BR>do while not cmd.eof <BR>bigclassid= cmd("bigclassid") <BR>bigclassname = cmd("bigclassname") <BR>%> <BR>"><%=bigclassname%> <BR><% <BR>cmd.movenext <BR>loop <BR>end if <BR>cmd.close <BR>set cmd = nothing <BR>%> <BR> <BR><div id="subclass"> <BR> <br><br><% <BR>set cxd = conn.execute("select * from smallclass where bigclassid=" & tempid) <BR>if not cxd.eof then <BR>do while not cxd.eof <BR>smallclassid= cxd("smallclassid") <BR>smallclassname = cxd("smallclassname")%> <BR>"><%=smallclassname%> <BR><% <BR>cxd.movenext <BR>loop <BR>cxd.close <BR>set cxd = nothing <BR>else <BR>html = "暂无小类" <BR>response.write html <BR>end if <BR>%> <BR> <BR>



ajax.js 代码

 <BR>// JavaScript Document <BR>function createxmlhttp() <BR>{ <BR>xmlhttpobj = false; <BR>try{ <BR>xmlhttpobj = new XMLHttpRequest; <BR>}catch(e){ <BR>try{ <BR>xmlhttpobj=new ActiveXObject("MSXML2.XMLHTTP"); <BR>}catch(e2){ <BR>try{ <BR>xmlhttpobj=new ActiveXObject("Microsoft.XMLHTTP"); <BR>}catch(e3){ <BR>xmlhttpobj = false; <BR>} <BR>} <BR>} <BR>return xmlhttpobj; <BR>} <br><br>funct<span>!本文来源gaodai#ma#com搞*!代#%^码网5</span><pre>搞gaodaima代码

ion getsubcategory(bigclassid){
if(bigclassid==0){
document.getElementById(“subclass”).innerHTML=”选择二级分类”;
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 代码

 <BR><%@language="vbscript" codepage="936"%> <BR><!---ecms -ecms #include file="conn.asp"--> <BR><% <BR>response.charset="gb2312" <BR>bigclassid=safe(request.querystring("bigclassid")) <BR>if bigclassid"" then <BR>set re=new regexp <BR>re.ignorecase=true <BR>re.global=false <BR>re.pattern = "^[0-9]{1,3}$" <BR>if not re.test(bigclassid) then <BR>response.write "非法参数" <BR>response.end <BR>end if%> <br><br><%on error resume next <BR>set p = conn.execute("select * from smallclass where bigclassid=" & bigclassid) <BR>if err then <BR>err.clear <BR>response.write "查询出错" <BR>response.end <BR>end if <BR>if not p.eof then <BR>html = ""&vbnewline <BR>do while not p.eof <BR>html = html&""&p("smallclassname")&""&vbnewline <BR>p.movenext <BR>loop <BR>html = html&"" <BR>else <BR>html = "暂无小类" <BR>end if <BR>p.close <BR>set p = nothing <BR>conn.close <BR>set conn = nothing <BR>response.write html <BR>html = "" <BR>end if <BR>%> <BR>

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:基于asp+ajax和数据库驱动的二级联动菜单_php技巧
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址