有什么办法让网页都能实时得到更新数据吗? ( 积分: 0 )

  • 主题发起人 主题发起人 wangpinggang
  • 开始时间 开始时间
W

wangpinggang

Unregistered / Unconfirmed
GUEST, unregistred user!
最近用c#做一个B/S实时监控系统,所有数据要求5s更新,
最初的方法是用<meta http-equiv=&quot;refresh&quot;
content=&quot;5&quot;>,
但不理想,尤其是加载图形时明显闪烁,
怎样更好,可否不用<meta http-equiv=&quot;refresh&quot;
content=&quot;5&quot;>
 
最近用c#做一个B/S实时监控系统,所有数据要求5s更新,
最初的方法是用<meta http-equiv=&quot;refresh&quot;
content=&quot;5&quot;>,
但不理想,尤其是加载图形时明显闪烁,
怎样更好,可否不用<meta http-equiv=&quot;refresh&quot;
content=&quot;5&quot;>
 
可用javascript 做一个定时器
<script language=&quot;JavaScript&quot;>
var staDate = 300;//单位:秒.1天=86400秒,1小时=3600秒
var startTime = (new Date()).getTime();
var Temp;
var timerID = null;
var timerRunning = false;
function time1(){
now = new Date();
var ts=parseInt((startTime-now.getTime())/1000)+staDate;
var shengdate = 0;
var shenghour = 0;
var shengminu = 0;
var shengsecon = 0;
if(ts < 0){
ts = 0;
CurHour = 0;
CurMinute = 0;
CurSecond = 0;}
else
{
shengdate =parseInt(ts/86400);//剩余天数
ts = ts - shengdate * 86400;
shenghour = parseInt(ts/3600);
ts = ts - shenghour * 3600;
shengminu = parseInt(ts/60);
shengsecon = ts - shengminu * 60;}
if(shenghour < 10) shenghour = '0' +shenghour;
if(shengminu < 10) shengminu = '0' +shengminu;
if(shengsecon<10) shengsecon='0'+shengsecon;
if( shengdate > 0 )
shengdate = shengdate + &quot;天&quot;
;
else
shengdate = &quot;&quot;;
if( shenghour > 0 )
shenghour = shenghour + &quot;小时&quot;
;
else
{
if( shengdate != &quot;&quot;
)
shenghour = &quot;00小时&quot;;
else
shenghour = &quot;&quot;;}
if( shengminu > 0 )
shengminu = shengminu + &quot;分钟&quot;
;
else
{
if( shengdate !=&quot;&quot;
|| shenghour != &quot;&quot;)
shengminu = &quot;00分钟&quot;;
else
shengminu = &quot;&quot;;}
if( shengsecon > 0 )
shengsecon = shengsecon + &quot;秒&quot;
;
else
{
if( shengdate !=&quot;&quot;
|| shenghour != &quot;&quot;
|| shengminu != &quot;&quot;)
shengsecon = &quot;00秒&quot;;
else
shengsecon = &quot;&quot;;}
//if (shengdate == '') {
Temp=shengdate+shenghour+shengminu+shengsecon ;
//}else
{
//Temp=shengdate+shenghour;}
if(shengdate <=0 &amp;&amp;
shenghour<=0 &amp;&amp;
shengminu<=0 &amp;&amp;
shengsecon <=0)
{
Temp = &quot;结束&quot;;
document.getElementById('time').value=Temp;
stopclock();
alert(&quot;时间已经到了!&quot;);
location.href=&quot;index.aspx&quot;;

}
if (document.getElementById('time'))do
cument.getElementById('time').value=Temp;
timerID = setTimeout(&quot;time1()&quot;,1000);
timerRunning = true;}
var timerID = null;
var timerRunning = false;
function stopclock()
{
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;
}
function tingclock(){
stopclock();
time1();}
function onloadall(){
tingclock();
try{
chushi();
}
catch(e){
}}
try{
onload=onloadall();}
catch(e){}
</script>
 
好,帮顶


--------签名档---------------------------

比肩国内顶尖源码下载站点 -> 源码我爱你

http://www.source520.com
http://www.source520.net
80G源码电子书免费免注册下载,大量精辟技术文档库随时更新
******************************************************************
附:为了站点持续发展,现有本站近年来收藏的大量大型商业源码低价出售,
详情请进入以下链接查看:
http://www.source520.com/building_delphi.htm

浏览商业代码请从如下URL进入查看实物:
1.商业源码库1: ftp://source520see3:browse@61.152.199.245/
2.商业源码库2: ftp://source520see2:browse@61.152.199.245/
 
后退
顶部