Pass an additional counter as parameter to a callback
<p>I have a <code>$("").load</code> call to get data and dump it into several divs. Each div has a unique ID that I track with an index variable inside a For loop. I do several ajax calls inside this loop. In the call back function I want to use the value of this index again. However by the time the callback executes, the for loop is already finished the index variable always has the top limit value for the loop. </p>

<p>How can I pass the value to this index to the callback function?</p>

<p>EDIT:</p>

<pre><code>for (var i=1;i&lt;=daysNum;i++)
{


    var tomorrow = new Date();
    tomorrow.setDate(tomorrow.getDate() + i); 


    var tmd=(tomorrow.getMonth()+1)+'/'+(tomorrow.getDate())+'/'+tomorrow.getFullYear();
    var tmdurl=(tomorrow.getMonth()+1)+'%2F'+(tomorrow.getDate())+'%2F'+tomorrow.getFullYear();

    $("#events").append("&lt;div&gt;&lt;div id='event"+i+"'&gt;&lt;/div&gt;&lt;div id='date"+i+"'&gt;"+tmd+"&lt;/div&gt;&lt;/div&gt;");
    $("#event"+i).load(seicalendarurl+"/calendar.aspx?CalendarDate="+tmdurl+"&amp;CalendarPeriod=Day .ms-cal-tdayitem, .ms-cal-alldayevent"

        ,  function (data){
             if($("event"+i).html()=="")
                $("date"+i).html("");

           }
    );

}
</code></pre>
