0

I'm loading some content inside a div with setInterval, and I don't want it to run everytime so I need to check if the content has changed from the last time it ran.

Here's what I'm currently using that's not working

var auto_refresh = setInterval(
function() {
    $('#loaddiv').load('/wzha/reload.php');
    $('#loaddiv').change(function() {
        var dddd = $('#loaddiv').text();
        alert(dddd);
    });
}, 1000);

Example:

reload.php is just <?php echo 'something here'; ?>. When I save reload.php, it needs to put something here in to the #loaddiv. It should not load the div anymore until I re-save reload.php to something else.

  • Not sure I get this, changed how, and only form elements, like inputs, have a change event ? – adeneo Apr 02 '13 at 21:46
  • are you changing this locally, or wanting to see if the data on the server's changed? – Marc B Apr 02 '13 at 21:47
  • reload.php is just ``. When I save reload.php, it needs to put `something here` in to the `#loaddiv`. It should not load the div anymore until I re-save reload.php to something else. – Christian Rankin Apr 02 '13 at 21:51
  • Why don't you save the contents of reload.php as a variable, and every time you call the function, check to see if the old variable matches the new one. If they are the same then don't update, if they are different, then you can update – Jako Apr 02 '13 at 21:56
  • http://stackoverflow.com/questions/3233991/jquery-watch-div or http://stackoverflow.com/questions/1091661/detect-element-content-changes-with-jquery – crafter Apr 02 '13 at 22:03

1 Answers1

1

Maybe something like :

var content,
    auto_refresh = setInterval(function() {
        $.get('/wzha/reload.php&r=' + (new Date()).getTime(), function(data) {
            if (data != content) {
                content = data;
                $('#loaddiv').html(data);
            }
        });
}, 1000);
adeneo
  • 312,895
  • 29
  • 395
  • 388