Auto refresh div causing browser to hang

会有一股神秘感。 提交于 2020-01-07 09:04:16

问题


I am working on a project using code igniter framework and one part of it is to auto refresh a div. However, after it auto refreshes the first or second time, the browser seems to slow down and eventually hangs. I've tried two methods of auto refreshing, these are the codes I used.

First method using setInterval, refresh every 1 minute:

<script>
$(document).ready(function()
{
    window.setInterval(refreshDiv, 100000);
});

var refreshDiv = function()
{
    $('#lot_info').load('<?php echo base_url();?>index.php/Home/display_lot_table');
};
</script>

Second method using setTimeout, refresh every 1 minute:

$(document).ready(function()
{
    refresh();
});

function refresh()
{
    setTimeout(function()
    {
        $('#lot_info').load('<?php echo base_url();?>index.php/Home/display_lot_table');
        refresh();
    }, 100000);
}

One thing I noticed using chrome's developer tools under the Network tab, the browser keeps requesting(which is expected) but the server does not return any data back. This piles up and causes the browser to hang.

Any help on this?

来源:https://stackoverflow.com/questions/32623590/auto-refresh-div-causing-browser-to-hang

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