Ajax按需读取数据生成下级菜单

时间:2021-05-28

jilian.htm
复制代码 代码如下:
<scriptlanguage="javascript">
varhttp_request=false;
functionsend_request(url){//初始化,指定处理函数,发送请求的函数
http_request=false;
//开始初始化XMLHttpRequest对象
if(window.XMLHttpRequest){//Mozilla浏览器
http_request=newXMLHttpRequest();
if(http_request.overrideMimeType){//设置MIME类型
http_request.overrideMimeType("text/html");
}
}
elseif(window.ActiveXObject){//IE浏览器
try{
http_request=newActiveXObject("Xsxml2.XMLHTTP");
http_request.setRequestHeader("Content-Type","text/xml");
http_request.setRequestHeader("Content-Type","gb2312");
}
catch(e){
try{
http_request=newActiveXObject("Microsoft.XMLHTTP");
http_request.setRequestHeader("Content-Type","text/xml");
http_request.setRequestHeader("Content-Type","gb2312");
}
catch(e){
}
}
}
if(!http_request){//异常,创建对象实例失败
window.alert("不能创建XMLHttpRequest对象实例");
returnfalse;
}
http_request.onreadystatechange=processRequest;
//确定发送请求的方式和URL以及是否同步执行下段代码
http_request.open("GET",url,true);
http_request.send(null);
}
//处理返回信息的函数
functionprocessRequest(){
if(http_request.readyState==4){//判断对象状态
if(http_request.status==200){//信息已经成功返回,开始处理信息
document.getElementById(currentPos).innerHTML=http_request.responseText;
}
else{//页面不正常
alert("您所请求的页面有异常");
}
}
}
functionshowRoles(obj){
document.getElementById(obj).parentNode.style.display="";
document.getElementById(obj).innerHTML="正在读取数据..."
currentPos=obj;
send_request("jilian_data.asp?playPos="+obj);
}
</script>

<tablewidth="200"border="0"cellspacing="0"cellpadding="0">
<tr>
<tdheight="20">
<ahref="javascript:void(0)"onclick="showRoles('pos_1')">经理室
</a>
</td>
</tr>
<trstyle="display:none">
<tdheight="20"id="pos_1">&nbsp;</td>
</tr>
<tr>
<tdheight="20">
<ahref="javascript:void(0)"onclick="showRoles('pos_2')">开发部</a>
</td>
</tr>
<trstyle="display:none">
<tdid="pos_2"height="20">&nbsp;</td>
</tr>
</td>
</table>

jilian_data.asp
复制代码 代码如下:
<%@LANGUAGE="VBSCRIPT"CODEPAGE="936"%>
<%
playPos=request("playPos")
ifplayPos="pos_1"then
Response.Write("&nbsp;&nbsp;jingli<br>&nbsp;&nbsp;副总经理")
endif
ifplayPos="pos_2"then
Response.Write("&nbsp;&nbsp;总工程师<br>&nbsp;&nbsp;软件工程师")
endif
%>



声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章