setInterval does not seem to be working?

拟墨画扇 提交于 2019-12-20 06:02:51

问题


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>

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?


回答1:


Try putting quotes around your function:

setInterval('setRooms()', 10000);

Alternatively change your method to:

var setRooms = function()

and you can then use:

setInterval(setRooms, 10000);



回答2:


setInterval(setRooms, 10000);



来源:https://stackoverflow.com/questions/8772791/setinterval-does-not-seem-to-be-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!