You can bundle up that logic in a clean way with code like this: function multiLoad( arglist, callback ) { var results = [], n = arglist.length; $.each( arglist, function( i, arg ) { $( arg[0] ).load( arg[1], arg[2], function() { results[i] = arguments; if( ! --n ) callback( results ); }); }); }
Call it like this (I assume your { VAR: var } objects are placeholders for actual argument objects): multiLoad( [ [ '#div1', 'scripts/generateA.php', { VAR: var } ], [ '#div2', 'scripts/generateB.php', { VAR: var } ], [ '#div3', 'scripts/generateC.php', { VAR: var } ], [ '#div4', 'scripts/generateD.php', { VAR: var } ] ], function( results ) { // all done - results is an array of the argument arrays // from the original callbacks, in the same order as they // are listed in this multiLoad call } ); That does a little more than you need, since you don't care about the callback function arguments, but it only adds one line of code in multiLoad() to support those arguments anyway. This is untested code, but it's almost identical to working code I've used for the same purpose in other situations - so barring typos it has a fair chance of working. -Mike > -----Original Message----- > From: jquery-en@googlegroups.com > [mailto:[EMAIL PROTECTED] On Behalf Of FreeKill > Sent: Monday, May 19, 2008 2:07 PM > To: jQuery (English) > Subject: [jQuery] Re: Multiple Load Callback > > > That would chain them all together though right, rather than > fire them all off at the same time? > > I was thinking of doing something maybe like this... > > var processesCompleted = 0; > var processesTotal = 4; > > $("#div1").load( "scripts/generateA.php", {VAR: var}, function( ) { > processesCompleted++; > performFinal( processesCompleted, processesTotal ); }); > > $("#div2").load( "scripts/generateB.php", {VAR: var}, function( ) { > processesCompleted++; > performFinal( processesCompleted, processesTotal ); }); > > etc etc > > function performFinal( completed, total ) { > if( completed == total ) { > // Do Final Work > } > } > > I know it's kind of nasty, but I think it might work. It > would be nice if there was some kind of queue structure that > could be passed 4 calls and have a callback that waits for > all 4 to finish... > > On May 19, 4:52 pm, "Alexandre Plennevaux" <[EMAIL PROTECTED]> > wrote: > > here is how i would try it, simply using the load() > function built-in > > callback parameter > > > > $("#div1").load( "scripts/generateA.php", {VAR: var} ,function(){ > > $("#div2").load( "scripts/generateB.php", {VAR: var}, function(){ > > $("#div3").load( "scripts/generateC.php", {VAR: var}, function(){ > > $("#div4").load( "scripts/generateD.php", {VAR: var} ); > > > > > > > > } ); > > } > > ); > > }); > > On Mon, May 19, 2008 at 10:39 PM, FreeKill > <[EMAIL PROTECTED]> wrote: > > > > > Hi, > > > > > I'm thinking there is something I'm just overlooking, but I hope > > > someone can help... > > > > > I have a set of load calls that are each made at document load: > > > > > $("#div1").load( "scripts/generateA.php", {VAR: var} ); > > > $("#div2").load( "scripts/generateB.php", {VAR: var} ); > > > $("#div3").load( "scripts/generateC.php", {VAR: var} ); > > > $("#div4").load( "scripts/generateD.php", {VAR: var} ); > > > > > What I want to do is make a 5th load call, but only once the > > > previous > > > 4 are completed. Is there a way to wrap a block of calls in a way > > > that a Callback function is called when they call complete? > > > > > I can think of some other, less optimal ways of getting this > > > accomplished, but I'm hoping someone might know how to do > it the way > > > I've got it going now. > > > > > Any suggestions? Your help is appreciated... > > > > -- > > Alexandre Plennevaux > > LAb[au] > > > > http://www.lab-au.com >