After populating an array with data, the information is logged into a database using a web service when the array reaches a specific record count. However, upon calling the web service, I encountered an error related to a parameter being passed:
Error
TypeError: citizens1[i] is undefined
data:{lat:citizens1[i].lat,
Code
//populate array
citizens1.push({lat:marker[index].getPosition().lat(),lng:marker[index].getPosition().lng(),socialSecurityNumber:global_citizens[index].socialSecurityNumber});
if(citizens1.length == 500){
console.log('500 records saved');
window.clearTimeout( timerHandle);
for(var i = 1; i = citizens1.length ; i++){
//array has data since the console.log works
console.log(citizens1[i].lat +',' +citizens1[i].lng+','+citizens1[i].socialSecurityNumber);
$.ajax({
type:'POST',
url:'logMovement.htm',
data:{lat:citizens1[i].lat,
lng:citizens1[i].lng,
socialSecurityNumber:citizens1[i].socialSecurityNumber},
dataType: 'json',
success:function(data){
if (data == false){
console.log('error occured in logging data');
}
}
});
}
citizens1 = [];
}