XMLHttpRequest ajax调用无刷新显示后台时间
2008-08-19 16:05
746 查看
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
代码
<script type="text/javascript" >
var timeout = null; //setInterval函数句柄
var xmlHttp = false; //
function SendRequest()
{
//xmlHttp = false;
if (window.ActiveXObject)
{
try
{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
else if (window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
else
{
alert('初始化错误!');
return;
}
var url = "Handler.ashx";
//var url = "Default2.aspx";
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange = ShowData;
xmlHttp.send(null);
}
function ShowData()
{
if(xmlHttp.readystate == 4)
{
if(xmlHttp.status == 200)
{
var tag = document.getElementById("container");
tag.innerHTML = "";
tag.innerHTML = xmlHttp.responseText;
}
}
}
//开始自动刷新
function Update()
{
timeout = window.setInterval("SendRequest()", 1000);//设定1秒调用一次Default2.aspx页面
}
//停止自动刷新
function StopUpdate()
{
if (timeout != null)
{
window.clearInterval(timeout);
}
}
</script>
<body onload="SendRequest();">
<form id="form1" runat="server">
<div>
<input type="button" value="Start Fresh" onclick="Update();"/>
<input type="button" value="Stop Fresh" onclick="StopUpdate();"/>
<input id="Button1" type="button" value="确定" onclick="SendRequest();"/>
</div>
</form>
<div id="container"><!--容器--></div>
</body>
</html>
<head runat="server">
<title>无标题页</title>
</head>
代码
<script type="text/javascript" >
var timeout = null; //setInterval函数句柄
var xmlHttp = false; //
function SendRequest()
{
//xmlHttp = false;
if (window.ActiveXObject)
{
try
{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
else if (window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
else
{
alert('初始化错误!');
return;
}
var url = "Handler.ashx";
//var url = "Default2.aspx";
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange = ShowData;
xmlHttp.send(null);
}
function ShowData()
{
if(xmlHttp.readystate == 4)
{
if(xmlHttp.status == 200)
{
var tag = document.getElementById("container");
tag.innerHTML = "";
tag.innerHTML = xmlHttp.responseText;
}
}
}
//开始自动刷新
function Update()
{
timeout = window.setInterval("SendRequest()", 1000);//设定1秒调用一次Default2.aspx页面
}
//停止自动刷新
function StopUpdate()
{
if (timeout != null)
{
window.clearInterval(timeout);
}
}
</script>
<body onload="SendRequest();">
<form id="form1" runat="server">
<div>
<input type="button" value="Start Fresh" onclick="Update();"/>
<input type="button" value="Stop Fresh" onclick="StopUpdate();"/>
<input id="Button1" type="button" value="确定" onclick="SendRequest();"/>
</div>
</form>
<div id="container"><!--容器--></div>
</body>
</html>
相关文章推荐
- .net使用Javascript XMLHttpRequest在前台调用后台方法
- js+xmlHttpRequest实现无刷新二级级联菜单(ajax原始)
- ajax简单实例(js内产生xmlHttpRequest,它和servlet交互返回xml显示在页面)
- 实现jquery.ajax及原生的XMLHttpRequest调用WCF服务的方法
- C#源码刷新网页 最小化托盘http get和post请求配置保存版权时间限制定时调用 单实例运行,如果已经运行则激活窗口到最前显示
- ajax XMLHttpRequest.readyState: 状态码 0 - (未初始化)还没有调用send()方法 解决了
- Ajax简单应用示例: XMLHttpRequest对象实例化方式及调用
- 使用 XMLHttpRequest 实现 Ajax 四:调用 Webservice
- 在微信中调用ajax出现的问题,XMLHttpRequest对象没有初始化
- Ajax¬—XMLHttpRequest实现页面的部分刷新
- spring mvc + xmlHttpRequest2.0 实现无刷新上传文件,带进度条和剩余时间
- 实现jquery.ajax及原生的XMLHttpRequest调用WCF服务的方法
- 运用Ajax的xmlHttpRequest对象异步与后台交互并提示交互结果
- ajax xmlhttprequest使用post传参数并向后台获取数据
- 实现jquery.ajax及原生的XMLHttpRequest跨域调用WCF服务的方法
- AJAX对象调用(XML HTTP Request)
- 定时请求php 后台 AJAX 请求,在页面中倒计时,和显示刷新时间
- Ajax无刷新方法纵览(1)—XMLHttpRequest对象
- ajax第一课(XMLHttpRequest向后台传字符串)
- Javascript (Ajax)给XMLHttpRequest设置超时时间