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); > > }