I have a function that sends data that is in a vector with an http post, so what I do is go through the vector with a for cycle and I send the data to the database, the problem I have is that the data is arriving in disorder to the database, that is, first the position 2 of the vector rises, then the 4, and thus, that is, they are rising in a random way. This is the code.
$scope.enviarlimites = function (){
var nombreLimite = document.getElementById('nombre').value;
var idMapa = document.getElementById('mapa_id').value;
if($scope.numerodepuntos==0 || $scope.numerodepuntos==null || nombreLimite==null || nombreLimite==""){
swal({
title: "Error",
text: "Debe ingresar todos los datos del mapa.",
icon: "error"
})
}else{
for(var i=0; i<$scope.numerodepuntos; i++){
var latitudbd = $scope.vectorCoordenadas[i].lat;
var longitudbd = $scope.vectorCoordenadas[i].lng;
var nombrelimitebd = nombreLimite+i;
$http.post("/territoriosinteligentes/enviarlimites", {nombre: nombrelimitebd, latitud: latitudbd,
longitud: longitudbd, identificador: nombreLimite, mapa_id: idMapa}).then(function(response)
{
$scope.status = response.status;
$scope.data = response.data;
swal({title: "Cargando Limites",text: "Por favor espere.",icon: "success"})
},
function(response) {
$scope.data = response.data || 'Request failed';
$scope.status = response.status;
swal({
title: "Error",
text: "No se pudo hacer el registro de los limites, debe ingresar todos los datos",
icon: "error"
})
})
}
}
}