What's the easiest / most efficient way to pause setInterval while data is loading? JavaScript/Jquery -
so have js interval doing load command on script.. , displays loaded data on div..
everything perfect until put project online , saw issue (in background)..
since setinterval needs set @ 1 second interval , , lot of times time takes data load more 1 second, see load stacking happening in background... since setinterval continues fire $.load() calls every second regardless of loaded data..
i thinking of setting global variable "is_loading" add function in interval, skip rest of routine incase "is_loading" true, .. once recent load call completes, sets is_loading = false..
this way interval keeps firing / second w/o load calls stacking in background...
however, since have several intervals doing loads on page (pls dont ask why lolz) find quite tedious w/ every interval.. therefore wondering there can "globally" event listener of sort current unfinished loading/get/post happening on page?
suggestions great
like others have said, use settimeout
make new request whenever request completes.
for dealing multiple requests on timer, recommend making sort of master timer/scheduler in order decrease amount of settimeouts running over. article google helpful me when doing similar:
http://googlecode.blogspot.com/2009/07/gmail-for-mobile-html5-series-using.html