62,268
社区成员
发帖
与我相关
我的任务
分享
var xmlhttp;
function createxmlhttp()
{
if( typeof( XMLHttpRequest ) != "undefined" )
{
xmlhttp = new XMLHttpRequest();
}
else
{
try
{
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){}
}
}
}
function startrequest(url,arg,syn,cation)
{
if (syn == 1)
syn = false;
else
syn = true;
createxmlhttp();
xmlhttp.open("POST",url,syn);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
xmlhttp.onreadystatechange=function ()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
cation(xmlhttp.responseText);
}
};
xmlhttp.send(arg);
}
var timeID;
function setproc()
{
startrequest('/api/check.ashx','type=username&username='+username,1,function (response){
//这里写你对操作返回结果的处理response是返回的结果
});
return true;
}
function begintime() {
timeID = window.setInterval("setproc()", 5000);
return true;
}
function stoptime() {
clearInterval(timeID);
return true;
}
<body onload="begintime()">
</body>
<script type="text/javascript">
var timeID;
function setproc()
{
//可以结合一般处理程序操作你的下半部分
return true;
}
function begintime() {
timeID = window.setInterval("setproc()", 5000);
return true;
}
function stoptime() {
clearInterval(timeID);
return true;
}
</script>
<div>
//你的上面部分内容
</div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Timer ID="Timer1" runat="server" Interval="5000" ontick="Timer1_Tick">
//Interval=5000是你要设置的操作间隔时间,ontick="Timer1_Tick"是你的操作的方法
</asp:Timer>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div>
//你自己的前端显示内容,要刷新的部分
</div>
</ContentTemplate>
</asp:UpdatePanel>
//C#后台操作
protected void Timer1_Tick(object sender, EventArgs e)
{
//你看书要处理刷新操作
}