Search code examples
jqueryajaxdelay

ajax starts getting delayed responses


after the page being open for some time this ajax request gets a lot slower or doesn't work

 $.ajax({  
  type: "POST",  
  url: "atuamae.org/send.php",  
  data: dataString,  
  success: function() {  
  showmessages()
  //podia-se meter o texto desaparecer suavemente por baixo..
  }  
 });  

there is also this other function runing:

  function showmessages(){
  $("#messages").load('atuamae.org/show-messages-encomendar.php');
   setTimeout('showmessages()',15000);
  }

are they interfering with each other? is data being accumulated somehow?

p.s. for some reason this affects are more significant in chrome than in Firefox


Solution

  • Each time you call showmessages() yourself or make that ajax call which calls it, it starts a new loop of calling showmessages() every 15 seconds.

    So, if you call that ajax call 10 times, you will end up with 10 timers calling showmessages() every 15 seconds. If you call the ajax call 30 times, you will end up with 30 timers calling showmessages() every 15 seconds which means it will be being called every 1/2 second. Yes, things would slow down a lot.

    Do you really means for showmessages() to call itself indefinitely every 15 seconds?