> 后端 > php > 基于asp+ajax和数据库驱动的二级联动菜单_php技巧 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>