首页 > 开发 > AJAX > 正文

Ajax按需读取数据生成下级菜单

2024-09-01 08:32:01
字体:
来源:转载
供稿:网友


<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 cellspacing="0" cellpadding="0">
<tr>
<td>
<a href="javascript:void(0)">经理室
</a>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>
<a href="javascript:void(0)">开发部</a>
</td>
</tr>
<tr>
<td> </td>
</tr>
</td>
</table>

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表