-1

Problem:

I believe that .load is blocking but is intended to be asynchronous.

Code:

$(window).load(function(){
    $('#content').load('/ajax/databaseworking.php');
    setTimeout(function(){ $('#content').load('/ajax/databaseperform.php');}, 5000);
});
</script>

Further Details:

The code basically calls databaseworking.php to do some database maintenance. Every 5 seconds, an ajax call is made to get its progress.

I have checked my logs. databaseworking.php and databaseperform.php are being called. However, databaseperform.php is not being called periodically. In other words, its only being called once.

As a test, I commented out the databaseworking call. This lead to the the progress function being called per interval as intended. This makes me believe that there is a problem with load. Note I have checked and tested databaseworking.php and there shouldnt be an error in there.

Goaler444
  • 2,591
  • 6
  • 35
  • 53

2 Answers2

4

setTimeout will only run once. I believe you wanted to use setInterval which is a recurring timer

Reference: https://developer.mozilla.org/en-US/docs/DOM/window.setTimeout

charlietfl
  • 170,828
  • 13
  • 121
  • 150
  • Because of the difference between `setTimeout` and `setInterval` it is very likely that in this situation the OP would prefer using repeat `setTimeout` or `setInterval` – Andrew Hubbs Jan 04 '13 at 02:49
0

You need to set a new timeout in your function.

$(window).load(function(){
    var loadContent = function() {
      $('#content').load('/ajax/databaseperform.php');
      setTimeout(loadContent, 5000);
    };
    loadContent();
});

You can see why this is likely preferable to using setInterval here: https://stackoverflow.com/a/731625/330013

Community
  • 1
  • 1
Andrew Hubbs
  • 9,338
  • 9
  • 48
  • 71