Ajax按需讀取數(shù)據(jù)生成下級菜單
更新時(shí)間:2006年08月23日 00:00:00 作者:
jilian.htm
<script language="javascript">
var http_request=false;
function send_request(url){//初始化,指定處理函數(shù),發(fā)送請求的函數(shù)
http_request=false;
//開始初始化XMLHttpRequest對象
if(window.XMLHttpRequest){//Mozilla瀏覽器
http_request=new XMLHttpRequest();
if(http_request.overrideMimeType){//設(shè)置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){//異常,創(chuàng)建對象實(shí)例失敗
window.alert("不能創(chuàng)建XMLHttpRequest對象實(shí)例");
return false;
}
http_request.onreadystatechange=processRequest;
//確定發(fā)送請求的方式和URL以及是否同步執(zhí)行下段代碼
http_request.open("GET",url,true);
http_request.send(null);
}
//處理返回信息的函數(shù)
function processRequest(){
if(http_request.readyState==4){//判斷對象狀態(tài)
if(http_request.status==200){//信息已經(jīng)成功返回,開始處理信息
document.getElementById(currentPos).innerHTML=http_request.responseText;
}
else{//頁面不正常
alert("您所請求的頁面有異常");
}
}
}
function showRoles(obj){
document.getElementById(obj).parentNode.style.display="";
document.getElementById(obj).innerHTML="正在讀取數(shù)據(jù)..."
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')">經(jīng)理室
</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')">開發(fā)部</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> 副總經(jīng)理")
end if
if playPos="pos_2" then
Response.Write(" 總工程師<br> 軟件工程師")
end if
%>
復(fù)制代碼 代碼如下:
<script language="javascript">
var http_request=false;
function send_request(url){//初始化,指定處理函數(shù),發(fā)送請求的函數(shù)
http_request=false;
//開始初始化XMLHttpRequest對象
if(window.XMLHttpRequest){//Mozilla瀏覽器
http_request=new XMLHttpRequest();
if(http_request.overrideMimeType){//設(shè)置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){//異常,創(chuàng)建對象實(shí)例失敗
window.alert("不能創(chuàng)建XMLHttpRequest對象實(shí)例");
return false;
}
http_request.onreadystatechange=processRequest;
//確定發(fā)送請求的方式和URL以及是否同步執(zhí)行下段代碼
http_request.open("GET",url,true);
http_request.send(null);
}
//處理返回信息的函數(shù)
function processRequest(){
if(http_request.readyState==4){//判斷對象狀態(tài)
if(http_request.status==200){//信息已經(jīng)成功返回,開始處理信息
document.getElementById(currentPos).innerHTML=http_request.responseText;
}
else{//頁面不正常
alert("您所請求的頁面有異常");
}
}
}
function showRoles(obj){
document.getElementById(obj).parentNode.style.display="";
document.getElementById(obj).innerHTML="正在讀取數(shù)據(jù)..."
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')">經(jīng)理室
</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')">開發(fā)部</a>
</td>
</tr>
<tr style="display:none">
<td id="pos_2" height="20"> </td>
</tr>
</td>
</table>
jilian_data.asp
復(fù)制代碼 代碼如下:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
playPos=request("playPos")
if playPos="pos_1" then
Response.Write(" jingli<br> 副總經(jīng)理")
end if
if playPos="pos_2" then
Response.Write(" 總工程師<br> 軟件工程師")
end if
%>
相關(guān)文章
bootstrap select2 動態(tài)從后臺Ajax動態(tài)獲取數(shù)據(jù)的代碼
這篇文章主要介紹了bootstrap select2 動態(tài)從后臺Ajax動態(tài)獲取數(shù)據(jù)的代碼,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-12-12
Ajax讀取XML實(shí)現(xiàn)動態(tài)下拉導(dǎo)航
Ajax讀取XML實(shí)現(xiàn)動態(tài)下拉導(dǎo)航...2007-02-02
基于Jquery.history解決ajax的前進(jìn)后退問題
本文主要給大家介紹基于Jquery.history解決ajax的前進(jìn)后退問題,涉及到j(luò)query前進(jìn)后退相關(guān)方面的知識,本文內(nèi)容經(jīng)典,非常具有參考價(jià)值,特此把jquery前進(jìn)后退相關(guān)知識分享在腳本之家網(wǎng)站供大家參考2015-10-10
AJAX入門之深入理解JavaScript中的函數(shù)
AJAX入門之深入理解JavaScript中的函數(shù)...2006-06-06
Ajax在請求過程中顯示進(jìn)度的簡單實(shí)現(xiàn)
ajax技術(shù)在web應(yīng)用中使用非常頻繁,本文以asp.net MVC為示例,提供一種簡單的實(shí)現(xiàn)方式。ajax在請求過程中顯示進(jìn)度條,是怎么實(shí)現(xiàn)的呢?本文通過代碼和文字說明相結(jié)合的方式分享給大家。2015-09-09
[ASP.NET AJAX]Function對象及Type類的方法介紹
[ASP.NET AJAX]Function對象及Type類的方法介紹...2007-01-01
利用AjaxSubmit()方法實(shí)現(xiàn)Form提交表單后回調(diào)功能
ajaxSubmit()方法是JQuery Form表單插件中的方法,使用時(shí),需要在jsp或者h(yuǎn)tml頁面上,引入JQuery庫和Form插件。接下來通過本文給大家分享通過AjaxSubmit()方法實(shí)現(xiàn)Form提交表單后回調(diào)功能,感興趣的朋友跟隨腳本之家小編一起看看吧2018-05-05

