基于asp+ajax和数据库驱动的二级联动菜单_PHP教程

WBOY
풀어 주다: 2016-07-21 15:39:13
원래의
884명이 탐색했습니다.

index.asp 页面代码

复制代码代码如下:


set cmd = conn.execute("select bigclassid,bigclassname from bigclass")
tempid=cmd("bigclassid")
%>


"
response.write html
end if
%>



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=" ";
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 代码
复制代码代码如下:



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%>

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 = " "
else
html = " "
end if
p.close
set p = nothing
conn.close
set conn = nothing
response.write html
html = ""
end if
%>

www.bkjia.com true http://www.bkjia.com/PHPjc/321638.html TechArticle index.asp 页面代码 复制代码 代码如下: !--#include file="conn.asp" -- % set cmd = conn.execute("select bigclassid,bigclassname from bigclass") tempid=cmd("bigclassid") %...
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!