I'm trying to print through innerHTML some data got with the ajax call, but the global array elements it is not accesible in the done() promise.It is indeed undefined. Why does that happen?
<html>
<head></head>
<body>
<script src ="jquery.min.js"></script>
<script>
$(document).ready(function(){
var elements = document.getElementsByClassName("wind");
for(i=0;i<elements.length;i=i+1){
$.ajax({
type:"GET",
url:"http://api.openweathermap.org/data/2.5/weather?q="+elements[i].innerHTML+"&appid=7876b25bdca1397553df39ef3ea05fd1",
dataType: "json"
}).done(function(data){
elements[i].innerHTML = data.wind.speed; //elements[i] is undefined
});
//elements[i].innerHTML here elements[i] is OK but I don't have access to "data"
}
});
</script>
<div class="wind">Venice,it</div>
<div class="wind">Rome,it</div>
</body>