0

I have the following code. This should make Ajax requests in a loop. The return value should always be written in the respective HTML element.

for (var i = 0; i < activeTiles.length; i++){
    var tmpElement = activeTiles[i];
    $.ajax({
        url: '/data/get.php',
        type: 'POST',
        data: {
            tiles:tmpElement.dataset.tiles,
        },
        success: function(data) {
            console.log(i);
            tmpElement.innerHTML = data;
        }
    });
}

However, when returning, the first element is no longer considered. The variable i is also =3 on every return. Can I make the element stay the same until returned.

What am I doing wrong? Thank you for your answers.

0 Answers0