Auto refresh div causing browser to hang

2019-09-11 17:10发布

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?

0条回答
登录 后发表回答