我的jQuery出了什么问题

时间:2021-10-12 03:58:21

I'm trying to periodically refresh a .Net view. I get Missing ] after element list error Here's my code

我正在尝试定期刷新.Net视图。元素列表错误之后我得到了Missing这是我的代码

<script type="text/javascript">

$(document).ready(function () {
    window.setInterval(loadRings(), 5000);
});
    function loadRings() {
    $.ajax({
            url: "Rings/Index",
            context: document.body,
            success: function (msg) {
                $("#ajaxDiv").html(msg);
            }
        });
    }

Any idea what's going on?

知道发生了什么事吗?

UPDATE: The setInterval should be

更新:setInterval应该是

window.setInterval(loadRings, 5000);

window.setInterval(loadRings,5000);

3 个解决方案

#1


4  

window.setInterval(loadRings(), 5000);

should be

应该

window.setInterval(loadRings, 5000);

#2


6  

setInterval accepts a function reference. However, you are manually executing the function. Try:

setInterval接受函数引用。但是,您手动执行该功能。尝试:

window.setInterval( loadRings, 5000 );

#3


4  

window.setInterval(loadRings(), 5000);

you must pass the reference to a function, but you're making a function call there.

你必须将引用传递给函数,但是你在那里进行函数调用。

like this:

喜欢这个:

window.setInterval(loadRings, 5000);

#1


4  

window.setInterval(loadRings(), 5000);

should be

应该

window.setInterval(loadRings, 5000);

#2


6  

setInterval accepts a function reference. However, you are manually executing the function. Try:

setInterval接受函数引用。但是,您手动执行该功能。尝试:

window.setInterval( loadRings, 5000 );

#3


4  

window.setInterval(loadRings(), 5000);

you must pass the reference to a function, but you're making a function call there.

你必须将引用传递给函数,但是你在那里进行函数调用。

like this:

喜欢这个:

window.setInterval(loadRings, 5000);