0

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?

Community
  • 1
  • 1
kross
  • 475
  • 1
  • 11
  • 31
  • Is the script tag setting the interval/timeout inside of index.php/Home/display_lot_table? –  Sep 17 '15 at 06:15
  • @Terminus Nope it's at the view for both methods – kross Sep 17 '15 at 06:24
  • Are you sure base_url () is echoing out? Also ,you say 1 minute but than have interval of 10000 (10 seconds? ) is that for testing or something? –  Sep 17 '15 at 06:33
  • My bad, I missed one zero. And yes I'm sure base_url() is echoing out. – kross Sep 17 '15 at 06:34
  • @ebilgin When he does $().load () it uses ajax... hzq than I'm out. If I knew more about how codeigniter :/ the url seems weird to me but probably something to do with your setup (nitpick: 100000 for interval is 100 seconds you want 60000 for 1 minute;) –  Sep 17 '15 at 06:39
  • @Terminus Ohh right... sorry about that, I kept confusing myself. I'm sure the url works fine because of the first and second reload/refresh it works fine. However when it continues, no more data is being received so yeah I'm still working on it. Thanks anyway – kross Sep 17 '15 at 06:42

0 Answers0