Ajax异步刷新
注意:
1、<div id="iframe">显示刷新的内容</div>
2、调用异步刷新:javascript:OnLink('地址')
<!--ajax异步刷新-->
<script type="text/javascript">
//创建XMLHttpRequestc对象
var xmlHttp=false;
//判断浏览器
function createXMLHttpRequest(){
if(window.ActiveXObject){//IE浏览器
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){}
}
}else{//其他浏览器:如mozilla 的 fireFox(火狐) 或者 netscape 7
xmlHttp=new XMLHttpRequest();
}
}
//提交获得值后的方法
function OnShow(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
var info=xmlHttp.responseText;
document.getElementById("iframe").innerHTML=info;
}
}
}
//要调用的方法
function OnLink(URL){
createXMLHttpRequest();
xmlHttp.open("post",URL,true);
xmlHttp.onreadystatechange=OnShow;
xmlHttp.send(null);
}
</script>
相关文档:
页面代码:
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManage ......
ScriptManager.RegisterStartupScript(p1, this.GetType(), "click", "alert('ok')", true);//p1是updatepanel的id
ScriptManager.RegisterStartupScript(p1, this.GetType(), "click", "alert('ok')", true);//p1是updatepanel的id
......
先说通过javascript发送时的乱码问题,如果发送的是中文,就要用escape这个函数处理,比如:
=======================
var url="testurl.php?name="+"刚刚";
=======================
那么就要改成
=======================
var url="testurl. ......
最近一直在寻找一个比较方便好用的树控件,MyTree树控件并没有提供很多其他的功能,但在Ajax异步加载节点上实现的很简洁,留作备忘。
MyTree的下载地址:http://www.itplus.com.cn/myTree/
下载后 Demo:Ajax异步加载例子
Document:文档
......