关闭

Ajax二级动态菜单

1147人阅读 评论(0) 收藏 举报

//Multi_menu.htm

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>MULTI-MENU</title>
<script type="text/javascript">
var currentPos="";
var http_request=false;
function send_request(method,url){
http_request=false;

// inital HttpRequest
if(window.XMLHttpRequest){//Mozilla
http_request = new XMLHttpRequest();
if(http_request.overrideMimeType){//set MIME
http_request.overrideMimeType("text/xml");
}//END SET MIME
}
else if(window.ActiveXObject){//IE Browser,Use Lasted version

var MSXML = ['MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP'];
for(var n = 0; n < MSXML.length; n ++)
{
try{
http_request = new ActiveXObject(MSXML[n]);
http_request.setRequestHeader("Content-Type","text/xml");
http_request.setRequestHeader('Content-Type', 'text/html; charset=gb2312'); //Last version need set, and it lik iFrame
if (method.toUpperCase( )=="POST" ){//post method
http_request.setRequestHeader('Connection', 'close');
http_request.setRequestHeader('Content-type','application/x-www-form-urlencoded');
}
break;
}
catch(e){http_request  = false;}
}//End IE
}// End inital HttpRequest

if(!http_request){//Error, Creat object fail
 window.alert("Cannot create an XMLHTTP instance")
 return false;
}
http_request.onreadystatechange = processRequest;
//get post or head, and asychFlag??
http_request.open(method, url,true);
http_request.send(null);
}// End send_request()

function processRequest(){
if(http_request.readyState == 4){
if(http_request.status == 200){
document.getElementById(currentPos).innerHTML= http_request.responseText;
}
else{
alert("Your Reqeust Page Error")}
}
}// End processRequest()

function showRole(obj){
if(document.getElementById(obj).parentNode.style.display=="none"){
document.getElementById(obj).parentNode.style.display="";
document.getElementById(obj).innerHTML ="loading...";
currentPos =obj;
//alert("ok");
send_request("post","mm.asp?playPos="+obj);
}
else{
document.getElementById(obj).parentNode.style.display="none";
}
}//End showRole

</script>

</head>
<body>
<table width="75%" border="1">
  <tr>
    <td><a href="javascript: void(0)" onClick="showRole('pos_1')" >经理室</a></td>
  </tr>
  <tr style="display:none">
    <td id="pos_1">&nbsp;</td>
  </tr>
  <tr>
    <td><a href="javascript: void(0)" onClick="showRole('pos_2')">开发部</a></td>
  </tr>
  <tr style="display:none">
    <td id="pos_2">&nbsp;</td>
  </tr>
</table>
</body>
</html>

//mm.asp

<% response.Charset="GB2312" '实现中文输出的关键%>
<%
playPos = request("playPos")
if playPos="pos_1" then 
response.Write("总经理<br>副经理") ''可以用数据库技术进行相关处理
elseif playPos="pos_2" then
response.Write("总工程师<br>软工程师")
end if
%>//

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1409220次
    • 积分:20232
    • 等级:
    • 排名:第413名
    • 原创:448篇
    • 转载:1067篇
    • 译文:4篇
    • 评论:144条
    文章存档
    最新评论