I had been developing a real time chat system at my work and the chat system takes some time to load(makes an ajax call to the backend that fetches users details,chat message,chat room id ,chat user role id etc..).and also there are multiple chat rooms based on user roles. The challenge was to wait for all of data to load and then enable the chat system.
Solution :
The solution is to wait for x interval of time and then make a call x time to check if the data we require is loaded.
var intialloading=false; waitoperation(); var someinterval =setInterval(function(){ if(intialloading) { //clear the interval. ClearInterval(someinterval); } },2000) // call function every 2 secs function waitoperation() { //some call intialloading=true; }