the alerting is because of the asynchronous callback: it only triggers
success when it receives response from the server, and by that time i
already equals 5 (already looped multiple times), I think.
Why you do not get that last page beats me, try  for (var i=1;i<6;i+
+)

David Decraene
http://ontologyonline.org


On Dec 19, 8:42 am, "Sam Sherlock" <[EMAIL PROTECTED]> wrote:
> 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

Reply via email to