Probably when Apple tried to get into the browser business too. 

-----Original Message-----
From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Wizzud
Sent: Monday, October 15, 2007 12:24 PM
To: jQuery (English)
Subject: [jQuery] Re: How to bind data to the ajax callback function?


It's not ambiguous at all.
Your problem is not with the $.get() but with the code around it.
$.get() does exactly what it is intended to do - it fetches a single 'page'
(of some sort) and provides you with the mechanism for handling that page
when successfully retrieved.
You are trying to handle multiple $.get()s in a single loop, with each
retrieved 'page' (presumably) being handled differently, and in the process
of doing so you're getting the scope of some variables mixed up. That's all.

If you really want to minimise it, and you really only have a loop of 2,
then ...

var url='http://foo.bar/?param=';
$.each([0,1],function(i,j){
    $.get(url+j, function(html){
        alert(j);
      });
  });

On Oct 14, 2:10 pm, arphenlin <[EMAIL PROTECTED]> wrote:
> It's so ambagious. I really hope jQuery can provide a *userData* 
> parameter like this:
> jQuery.get( url, [data], [callback], [userData] )
>
> Then I can achieve my goal with this way:
> for(var i=0; i<2; i++){
>     $.get(url+i, function(html, userData){
>         doit(html, userData['tag']); // userData was bound to ajax 
> callback
>     }, {'tag': i});
>
> }
> Wizzud wrote:
> > var url='http://foo.bar/?param=';
> > for(var i=0; i<2; i++){
> >     submitAjax(i);
> > }
> > function submitAjax(i){
> >     $.get(url+i, function(html){
> >         doit(html, i);
> >     });
> > }
> > function doit(html, tag){
> >     alert(tag);
> > }
>
> > On Oct 13, 11:04 am, arphenlin <[EMAIL PROTECTED]> wrote:
> > > Below is an example to use jQuery.get() to get some html data.
> > > I expect that "0", "1" (or "1", "0") are displayed, however, it 
> > > displayed "2", "2".
> > > How can I do?
>
> > > var url='http://foo.bar/?param=';
> > > for(var i=0; i<2; i++){
> > >     $.get(url+i, function(html){
> > >         doit(html, i); // bind 'i' to the callback function
> > >     });
>
> > > }
>
> > > function doit(html, tag){
> > >     alert(tag);
>
> > > }




Reply via email to