DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> AJAX入門 >> AJAX基礎知識 >> Ajax按需讀取數據生成下級菜單
Ajax按需讀取數據生成下級菜單
編輯:AJAX基礎知識     
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
%>



XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved