closure inside a for loop – callback with loop variable as parameter [duplicate]
This is a pretty standard problem with closures. When you do this: function(data, textStatus) { test(data, textStatus, idx); } You’re binding a reference to idx but not to the value of idx. So, by the time your callback gets called, the loop will have finished and idx will be 16 in all of the callbacks … Read more