Making a simple loop FOR
, I encountered a strange behavior that I could not understand.
The count is "lost" in the AJAX request, keeping the incrementer value with the last one. The URL request always returns 200
and still does not influence anything for proper execution.
Is there anything related to variable scope?
for (i = 0; i < 60; i++) {
console.log("For:" + i);
var urlMapas = "http://servicomapas.ibge.gov.br/api/mapas/" + i + '/1';
$.ajax({
url: urlMapas,
dataType: "json",
success: function(data) {
console.log("AJAX:" + i);
}
});
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>