I have a code and i want to execute it in asynchronous manner, here is my code snippet
var arr = [1,2,7,4,5];
for(var i in arr)
{
var res = "";
var count =i;
$("#container").append("<div id='div_"+count+"'></div>");
$.get( qlink, function(retdata) {
res= retdata.value;
});
$("#div_"+count).html(res); // Last line
}
Everything is executing fine But the problem here is in the "Last line" what is does is it takes the value of count as 5 for every iteration. Any suggestion? I want the execution to be parallel and parallely want the variable scope to be confined to that iteration only.