views:

85

answers:

2

I'm trying to write a recursive jQuery statement that grabs some data and populates fields. However I don't want the next command to be executed until the current one is finished. I'm trying to do the below, however it doesn't seem to make it to the second run. Is there something I am doing wrong?

I kick it off by doing:

var arg = new Array();
arg[0]= 'id0';
arg[1]= 'id1';
arg[2]= 'id2';
arg[3]= 'id3';
arg[4]= 'id4';
arg[5]= 'id5';

grabMetrics('toggle=0', arg, 0);


function grabMetrics(url, locationAry, num){
alert(num);
$.ajax({
 type: "POST",
 url: "foo.php",
 data: url,
 success: function($this){
  $("#"+locationAry[num]).text($this);
  if(num<5){
   num++;
   grabMetrics('toggle='+num, locationAry, num);
  }
 }
});
}

Thank you in advance!

+1  A: 

Change this:

if(num>5){

to this:

if(num<5){
nickf
arg. sorry for wasting your time.
Frederico
+1  A: 

Shouldn't that be if(num < 5)?

Kenaniah