I'd say its a scope issue with the var i I am not a JS expert so this is not definitive
var I = 0, dt = 5; for (i=1;i<=dt;i++) { I = i; $.ajax({ type: "GET", url: "http://example.com/5740/"+i+"/page.html", dataType: "text", success: function(data){ alert(I); } })}; untested; I might either be barking up the wrong tree or I may have misunderstood the quest or some other wiser jQuerian may have more to say, all part of the learning curve :) On 18/12/2007, Ryura <[EMAIL PROTECTED]> wrote: > > > Got a problem when looping ajax requests. I have probably made a > mistake somewhere but I can't find it. > > dt=5; > for (i=1;i<=dt;i++) { > $.ajax({ > type: "GET", > url: "http://example.com/5740/"+i+"/page.html", > dataType: "text", > success: function(data){ > alert(i); > } > })}; > This alerts "5" 4 times. Interestingly, it correctly gets 4 pages: > http://example.com/5740/1/page.html > http://example.com/5740/2/page.html > http://example.com/5740/3/page.html > http://example.com/5740/4/page.html > > What is the solution? > Thanks, > Ryura >