Ajax按需讀取數(shù)據(jù)生成下級(jí)菜單
更新時(shí)間:2006年08月23日 00:00:00 作者:
jilian.htm
<script language="javascript">
var http_request=false;
function send_request(url){//初始化,指定處理函數(shù),發(fā)送請(qǐng)求的函數(shù)
http_request=false;
//開(kāi)始初始化XMLHttpRequest對(duì)象
if(window.XMLHttpRequest){//Mozilla瀏覽器
http_request=new XMLHttpRequest();
if(http_request.overrideMimeType){//設(shè)置MIME類(lèi)型
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)建對(duì)象實(shí)例失敗
window.alert("不能創(chuàng)建XMLHttpRequest對(duì)象實(shí)例");
return false;
}
http_request.onreadystatechange=processRequest;
//確定發(fā)送請(qǐng)求的方式和URL以及是否同步執(zhí)行下段代碼
http_request.open("GET",url,true);
http_request.send(null);
}
//處理返回信息的函數(shù)
function processRequest(){
if(http_request.readyState==4){//判斷對(duì)象狀態(tài)
if(http_request.status==200){//信息已經(jīng)成功返回,開(kāi)始處理信息
document.getElementById(currentPos).innerHTML=http_request.responseText;
}
else{//頁(yè)面不正常
alert("您所請(qǐng)求的頁(yè)面有異常");
}
}
}
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')">開(kāi)發(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ā)送請(qǐng)求的函數(shù)
http_request=false;
//開(kāi)始初始化XMLHttpRequest對(duì)象
if(window.XMLHttpRequest){//Mozilla瀏覽器
http_request=new XMLHttpRequest();
if(http_request.overrideMimeType){//設(shè)置MIME類(lèi)型
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)建對(duì)象實(shí)例失敗
window.alert("不能創(chuàng)建XMLHttpRequest對(duì)象實(shí)例");
return false;
}
http_request.onreadystatechange=processRequest;
//確定發(fā)送請(qǐng)求的方式和URL以及是否同步執(zhí)行下段代碼
http_request.open("GET",url,true);
http_request.send(null);
}
//處理返回信息的函數(shù)
function processRequest(){
if(http_request.readyState==4){//判斷對(duì)象狀態(tài)
if(http_request.status==200){//信息已經(jīng)成功返回,開(kāi)始處理信息
document.getElementById(currentPos).innerHTML=http_request.responseText;
}
else{//頁(yè)面不正常
alert("您所請(qǐng)求的頁(yè)面有異常");
}
}
}
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')">開(kāi)發(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)文章
ajax三級(jí)聯(lián)動(dòng)實(shí)現(xiàn)代碼
這篇文章主要為大家詳細(xì)介紹了ajax三級(jí)聯(lián)動(dòng)的實(shí)現(xiàn)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05
AJAX+Servlet實(shí)現(xiàn)的數(shù)據(jù)處理顯示功能示例
這篇文章主要介紹了AJAX+Servlet實(shí)現(xiàn)的數(shù)據(jù)處理顯示功能,結(jié)合實(shí)例形式分析了前臺(tái)ajax與后臺(tái)Servlet生成隨機(jī)數(shù)顯示的相關(guān)交互操作技巧,需要的朋友可以參考下2018-06-06
Ajax學(xué)習(xí)筆記---3種Ajax的實(shí)現(xiàn)方法【推薦】
下面小編就為大家?guī)?lái)一篇Ajax學(xué)習(xí)筆記---3種Ajax的實(shí)現(xiàn)方法【推薦】。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考2016-05-05
如何利用jQuery post傳遞含特殊字符的數(shù)據(jù)
在jquery中,解決數(shù)據(jù)傳遞處理的方法我們通常利用$.ajax或$.post,但是這里這里通常不能傳遞特殊字符,比如說(shuō):“<”,本文就幫大家解決如何傳遞這種含特殊字符的數(shù)據(jù),感興趣的朋友一起看下吧2015-10-10
PHP Ajax實(shí)現(xiàn)頁(yè)面無(wú)刷新發(fā)表評(píng)論
PHP Ajax實(shí)現(xiàn)頁(yè)面無(wú)刷新發(fā)表評(píng)論...2006-12-12
AJAX避免用戶(hù)重復(fù)提交請(qǐng)求實(shí)現(xiàn)方案
為了避免因某些原因用戶(hù)同時(shí)多次點(diǎn)擊按鈕,提交重復(fù)的請(qǐng)求,我們需要禁用請(qǐng)求提交按鈕,接下來(lái)與大家一起分享下實(shí)現(xiàn)方法2013-04-04
甩掉ashx和asmx使用jQuery.ajaxWebService請(qǐng)求WebMethod簡(jiǎn)練處理Ajax
這篇文章主要介紹了甩掉ashx和asmx使用jQuery.ajaxWebService請(qǐng)求WebMethod簡(jiǎn)練處理Ajax的相關(guān)資料,需要的朋友可以參考下2016-08-08

