I wrote this JS code :
var abils = document.getElementsByName('aggiunta_abil');
for (let i = 0; i < abils.length; i++) {
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
alert(abils[i].parentNode.parentNode.innerHTML);
if (xhttp.readyState == 4 || status == 200) {
abils[i].parentNode.parentNode.innerHTML = this.responseText;
}
}
var url = 'my url';
if(abils[i].value != '') url = url + 'id_abil' + '=' + abils[i].value + '&';
xhttp.open('GET', url, true);
xhttp.send();
}
}
My problem is that the alert stamps correclty the innerHTML of the node, but 2 lines after it says me that abils[i] is not defined. Even if I remove the if clause , keeping only the 2 instructions one after the other one , nothing changes : the alert keep working well but the abils[i].parentNode.parentNode.innerHTML = this.responseText;
no.
I also tryed with jquery for ajax , but nothing change : in the success function it says me that abils[i] is not defined.
I don't know what to do , please help me.