Inside the for loop am making the ajax call. For loop is not waiting until ajxa call got response, it incrementing the value to plus one so response is not updating to it's respective div.
Example: I have 'N'
no of divs with id divid0, divid1, divid2, divid3, divid4........ dividn.
In the loop(for(var i=0; i < n; i++)) first 'i' value is zero, I need to update my first ajax response to div which has id "divid0"
, but untill I got the ajax response in the loop 'i'
is incremented to one so my first ajax response is updating to div which has id "divid1"
instead of "divid0"
.
I overcome this problem using ajax synchronous call but the problem is I am unable to drag the page to bottom untill page is completely loaded. My web page contain around 10 slider so it is taking more than a min to load completely then only user can view the page. so I want user to drag to bottom of the page even while page loading(After minimum one slider is loaded).
Thanks in advance, Here is my code
for(var sliderId=0; sliderId < 6; sliderId++){
$.get('api url', {}, function(response){
if(!response){
$("#slider"+sliderId).html('Currently there is no items in this category');
} else{
if((response.results) && (response.results.length > 0)){
getInfo(response, sliderId);
}
}
});
}