setInterval似乎不起作用? [英] setInterval does not seem to be working?

查看:113
本文介绍了setInterval似乎不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码似乎不起作用。我正在尝试创建一个可用的聊天室动态列表,每10秒更新一次。我还希望用户能够设置peraminters来过滤将显示的房间。
我正在使用此代码,但由于某些原因它似乎无法运行。

This code does not seem to be working. I am trying to create a dynamic list of chat rooms available that updates every 10 seconds. I also want the user to be able to set peraminters to filter what rooms would be shown. I am using this code, and it does not seem to be working for some reason.

<script type="text/javascript"> 
function setRooms()
{
    console.log('ok');
    if($('#only').is(':checked'))
    {
     var checked = 1;   
    }
    else 
    {
    var checked = 0;    
    }
    if($('#open').is(':checked'))
    {
     var opened  = 1;   
    }
    else 
    {
    var opened = 0; 
    }
    $.post('backend/outputRooms', {
        fLevel : $('#flevel').val(), 
        sLevel : $('#slevel').val(),
        display : $('display').val(),
        Checked : checked,

        }, 
        function(data)
        {
            $('#text').html(data);
        }); 
}
$(document).ready(function(){
    setInterval(setRooms(), 10000);
    });
</script>

我排除了后端页面的问题,如console.log('ok')似乎并没有起作用。有什么帮助?

I have ruled out a problem with the backend page, as the console.log('ok') does not seem to be working as well. Any help?

推荐答案

尝试在函数周围加上引号:

Try putting quotes around your function:

setInterval('setRooms()', 10000);

或者将您的方法更改为:

Alternatively change your method to:

var setRooms = function()

然后你可以使用:

setInterval(setRooms, 10000);

这篇关于setInterval似乎不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆