Using ajax post, I am sending the current "i" value in a loop to another PHP page and then retrieving the same "i" value from that page. However, before being posted, the "i" value is somehow incremented by 1. When I check the output using console.log(data);
, it shows 2,..,100,1
. This result is unexpected as I was expecting 1,..,100
.
for (i = 1; i <= 100; i++) {
$.ajax({
type: 'POST',
url: '2.php',
data: { 'id': i } ,
success: function(data) {
//console.log(data);
}
});
}
Here is the content of 2.php:
<?php
echo $_POST['id'];
?>