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 ......
使用原始的XMLHttpRequest发出请求时,只能对Servlet和JSP操作
在JSP中创建3个function
1.createXmlHttpRequest----负责判断浏览器类型创建 XMLHttpRequest对象
var xmlHttpRequest;
function createXMLHttpRequest(){
// IE 浏览器
if(window.ActiveXObject){
&nbs ......
A.aspx页面放一个dropdownlist,在A.aspx.cs添加: this.drpSchool.Attributes.Add("onchange", "load(this.options[this.selectedIndex].value)");
在A.aspx页面添加如下脚本:
function load(state){
var oHttpReq = new ActiveXObject("MSXML2.XMLHTTP");
var oDoc = new ActiveXObject("MSXML2.DOMDocument");
......
1、区块的显示与隐藏
在进行ajax编程时,经常会用到div标签对页面元素进行布局,大致方法是,把界面分做几大块,有时候需要根据点击菜单显示相应的块及隐藏其他块,这时可简单设置div.style.display为block进行显示,div.style.dispaly为none进行隐藏。
2、界面元素命名
&nb ......
1.XMLHttpRequest对象
open("method","URL""[,asyncFlag[,"userName"[, "password"]]])
建立对服务器的访问。其中method参数可以使用GET、POST及PUT,URL参数既可以使用绝对地址,也可以使用相对地址,此外还包括与建立连接相关的三个参数
&nbs ......