I want to increment the value of a variable ii
, but its value does not change. If I move ii++;
before the alert
function call, it increases but the value set to #spanstatus
is always 0
.
How do I increment the value of ii
, and still access it before my $.ajax
call?
<html>
<span id="spanstatus"></span><br>
<script src="../js/jquery-1.12.4.min.js"></script>
<script>
var data = new FormData();
data.append('test', 'a');
data.append('test1', 'b');
data.append('test2', 'c');
function upload() {
$('#spanstatus').html('');
var ii=0;
for(var [name, value] of data) {
$('#spanstatus').append('<i>Uploading <b>"'+name+'"</b></i>...<span id="spanupload_'+ii+'">'+ii+'</span><br>');
$.ajax({
type:'POST',
method: 'POST',
timeout:2000,
url:'upload.php?val='+value,
dataType: "json",
data: value,
contentType: false,
cache: false,
processData:false,
// async: false,
success:function(response){
$('#spanupload_'+ii).html(ii+' OK');
alert(ii+'ok='+name);
ii++;
}
});
}
}
$(document).ready(function(){
upload();
});
</script>
</body>
</html>