Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do we need setTimeout for short polling?

If I want to implement short polling like this:

function firstCall(){
   $.ajax({
     ...
     success: function(response){
         if (response.OK == "OK"){
              secondCall();
         }else{
            firstCall();
         }
     }
  });

}

Will this be enough? or do I really need to surround the firstCall() in else clause with setTimeout ?Thanks

like image 516
user1012451 Avatar asked Mar 27 '26 12:03

user1012451


1 Answers

I recommend you to use a little timeout, because now you are creating a lot of traffic to your server. Ajax is fast and success will be executed very often.

So I recommend you to use setTimeout or setInterval instead!

like image 84
tuxtimo Avatar answered Mar 30 '26 01:03

tuxtimo