View Single Post
Old 12-12-2011, 11:52 PM   PM User | #4
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,462
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
Quote:
Originally Posted by jfreak53 View Post
Yeah, but you can only have X amount of max async calls in a browser at one time, I would max way out with the 625 calls that it makes to the script. Plus there's no way to know if their are 625 records or less or more.
you could only do one call at a time, you never need more than a dozen hanging out there at once...

you trigger the next call or batch of calls upon the arrival of a call.

i'm not sure what your server spits out, but i faced a related challenge doing a CMS content dump, from a mysql db. i used LIMIT to ask for 100 rows at a time, range specified in the url. if the result set came back with 100 entries, i incremented the range by 100. if it had fewer than 100 rows, that set was complete and i invoked the collector callback to save the collated results to a file.


to get started, i would break your code into more re-usable functions. get the logic out of the loop. once you get everything broken up, it will be much easier to start making it async.
in particular,
Code:
while(num1 <= num4) {
could be
Code:
function next(num1, num4) {
 if(num1>=num4){ return;}
 ...

also, i would look at the sql, you should be able to combine a lot of those queries before they are served. use joins to create a wider table of data to avoid repeated calls.


also, this line:
Code:
z = j.parseJSON(ajax('countPolCar', s.params.curdate, ''));
can be moved to before the while loop (or function), which saves an IO every loop.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Users who have thanked rnd me for this post:
jfreak53 (12-14-2011)