Ajax按需讀取資料產生下級菜單

來源:互聯網
上載者:User

jilian.htm 複製代碼 代碼如下:<script language="javascript">
var http_request=false;
function send_request(url){//初始化,指定處理函數,發送請求的函數
http_request=false;
//開始初始化XMLHttpRequest對象
if(window.XMLHttpRequest){//Mozilla瀏覽器
http_request=new XMLHttpRequest();
if(http_request.overrideMimeType){//設定MIME類型
http_request.overrideMimeType("text/html");
}
}
else if(window.ActiveXObject){//IE瀏覽器
try{
http_request=new ActiveXObject("Xsxml2.XMLHTTP");
http_request.setRequestHeader("Content-Type","text/xml");
http_request.setRequestHeader("Content-Type","gb2312");
}
catch(e){
try{
http_request=new ActiveXObject("Microsoft.XMLHTTP");
http_request.setRequestHeader("Content-Type","text/xml");
http_request.setRequestHeader("Content-Type","gb2312");
}
catch(e){
}
}
}
if(!http_request){//異常,建立對象執行個體失敗
window.alert("不能建立XMLHttpRequest對象執行個體");
return false;
}
http_request.onreadystatechange=processRequest;
//確定發送請求的方式和URL以及是否同步執行下段代碼
http_request.open("GET",url,true);
http_request.send(null);
}
//處理返回資訊的函數
function processRequest(){
if(http_request.readyState==4){//判斷對象狀態
if(http_request.status==200){//資訊已經成功返回,開始處理資訊
document.getElementById(currentPos).innerHTML=http_request.responseText;
}
else{//頁面不正常
alert("您所請求的頁面有異常");
}
}
}
function showRoles(obj){
document.getElementById(obj).parentNode.style.display="";
document.getElementById(obj).innerHTML="正在讀取資料..."
currentPos=obj;
send_request("jilian_data.asp?playPos="+obj);
}
</script>

<table width="200" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="20">
<a href="javascript:void(0)" onclick="showRoles('pos_1')">經理室
</a>
</td>
</tr>
<tr style="display:none">
<td height="20" id="pos_1"> </td>
</tr>
<tr>
<td height="20">
<a href="javascript:void(0)" onclick="showRoles('pos_2')">開發部</a>
</td>
</tr>
<tr style="display:none">
<td id="pos_2" height="20"> </td>
</tr>
</td>
</table>

jilian_data.asp 複製代碼 代碼如下:<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
playPos=request("playPos")
if playPos="pos_1" then
Response.Write(" jingli<br> 副總經理")
end if
if playPos="pos_2" then
Response.Write(" 總工程師<br> 軟體工程師")
end if
%>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.