2012-11-30 30 views
1

我有这样的代码到我的主视图文件:的Javascript轮询在web2py中

<html> 
      <head> 
      <script src="/app/static/js/jquery.js" type="text/javascript"> 
      <script type="text/javascript"> 
       jQuery(document).ready(function() { 
        window.setTimeout(function() { 
         var url = '{{=URL('monitor.load')}}'; 
         jQuery('#monitor').load(url); 
        }, 10000); 
       }); 
      </script> 
      </head> 

      <body> 
       <div id="monitor"></div> 
      </body> 
     </html> 

为了显示进入#monitor div标签从monitor.load文件中的数据:

{{=data}} 

但,它只在10秒后才将数据置1,然后它不会像我想要的那样每10秒更新一次数据...
如果数据在控制器中发生变化,或者在monitor.load文件中发生更改 什么也没有发生...

回答

4

如果您希望代码多次出现,您应该使用setInterval()

实施例:

setInterval("alert('hello!');", 500); 

此代码以上将执行代码alert('hello!');时被加载的页面,直到它被关闭从每500毫秒。

+1

是的,setInterval的工作就像一个魅力!,感谢兄弟... – chespinoza