Jquery code making browser busy?

Hi I am using this code to refresh files I have put in a wall system and then I am getting this file (main index file where this code is used) to show up in a block, My purpose was to only refresh the block where i am calling index file, but this code is also making favicon to blink every few seconds and i also see the browser showing waiting for www.mywebsite.com every few seconds, how can I fix it to only update the part of block and not the whole page. I hope this makes sense as this is my first post here. How can edit this code to use setTimeout may be? Thank you in advance :smile:

$(document).ready(function () {
interval = setInterval(updateDiv, 1000); }); function updateDiv() {
var letest_id = $("ul.pagination1 :first-child").attr('id').replace('record-', '');

$.ajax({
    method: 'GET',
    cache: false,
    url: 'url.php?load_s=ajax&group_id=<?php echo $g_i_s;?>&max_id=' + letest_id + '&ref=<?php echo time();?>',

    success: function (data) {

        if (data) {
            $('ul.pagination1').prepend(data).fadeIn('slow');
        }
    },

    error: function () {

        clearInterval(interval);
    }
});
var comid = $('#last_id_ajax').val();
$.ajax({
    method: 'GET',
    cache: false,
    url: 'url.php?group_id=<?php echo $g_i_s;?>&commentid=' + comid + '&ref=<?php echo time();?>',
    success: function (result) {
        if (result) {
            var divi = $(result).find(".imgd").attr('alt');
            var last_id_ajax_val = $(result).find(".cid").attr('id');
            $('#last_id_ajax').val(last_id_ajax_val);
            // alert(newcoment);
            $(divi).append(result).fadeIn('slow');
        }
    },

    error: function () {
        clearInterval(interval);
    }
}); }

Hi,

There is nothing that I can see in the code you posted, that would be causing the behaviour you describe.
Could you possibly provide a link to a page where we can see this in action?

Perhaps check the network monitor in developer panel (f12)

1 Like

hi the website link is http://www.virsapunjabi.com/index.php the code is working in comment system on main page.

Perhaps the problem lies in url.php which is called by ajax? Maybe it does something infinitely (Wild guess).

One second doesn’t seem like much of a delay. Try upping it to 5 seconds or longer

interval = setInterval(updateDiv, 5000);

I tried everything I can think of and that too. It just does the same thing after 5 seconds. but Thanks for replying everyone :smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.