This particular piece of code is responsible for populating an inner div within an image slider by making an Ajax call :
$.ajax({
type: "GET",
dataType: 'json',
url: $(this).attr('href')
}).done(function (result) {
// add thumbnails to lower slider
var correct_width = 0;
for (var $i = 0; $i < result[1].length; $i++) {
$('#lower_slider').append("<img src='" + result[1][$i]['image_thumb_src'] + "'>");
// calculate $('#lower_slider') width
$('#lower_slider').find('img').each(function () {
correct_width += $(this).outerWidth();
});
}
// set $('#lower_slider') width
$('#lower_slider').width(correct_width);
});
The function of this code performs flawlessly the second time it's run - indicating that there might be some race conditions at play. How can these be resolved?
p.s - I am aware that a similar query has been raised before, but none of the solutions suggested have proven effective in my case.
Thank you.