Web2py中的Javascript轮询
我的主视图文件中有以下代码:Web2py中的Javascript轮询,javascript,jquery,ajax,web2py,Javascript,Jquery,Ajax,Web2py,我的主视图文件中有以下代码: <html> <head> <script src="/app/static/js/jquery.js" type="text/javascript"> <script type="text/javascript"> jQuery(document).ready(function() {
<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>
但是,它在10秒后只放一次数据,然后它不会像我希望的那样每10秒更新一次数据…如果数据在控制器中更改,或在monitor.load文件中更改
没有发生任何事情…如果希望代码多次出现,则应使用
setInterval()
示例:
setInterval("alert('hello!');", 500);
上述代码将执行代码
alert('hello!')从页面加载到关闭,每500毫秒编码一次。如果希望代码多次出现,则应使用setInterval()
示例:
setInterval("alert('hello!');", 500);
上述代码将执行代码alert('hello!')代码>从页面加载到关闭,每500毫秒一次