谷歌浏览器jQuery问题

Google Chrome jQuery problems

本文关键字:问题 jQuery 谷歌浏览器      更新时间:2023-09-26

我有一个站点(在Grails中),它使用setInterval方法和jQuery定期提交表单(formRemote,Grails中的ajax forms)。它适用于所有浏览器(甚至在IE中),但有时在谷歌浏览器中不起作用。这是我正在使用的js的一个片段:

window.setInterval(updateGroupMessages,500)
function updateGroupMessages() {
    console.log('hello from updateGroupMessages');
    $(function(){$('#updateGroupMessagesBlock').submit();});
}

我已经检查了谷歌浏览器中的控制台,但没有错误消息。老实说,我不知道我做错了什么...

尝试更改顺序,以便先声明函数,然后为其设置间隔。

function updateGroupMessages() {
    console.log('hello from updateGroupMessages');
    $(function(){$('#updateGroupMessagesBlock').submit();});
}
window.setInterval(updateGroupMessages,500)

尝试将闭包从.submit()行移动到整个代码块:

$(function() {
    window.setInterval(updateGroupMessages,500);
    function updateGroupMessages() {
        console.log('hello from updateGroupMessages');
        $('#updateGroupMessagesBlock').submit();
    }
});