0

我有一个函数,根据存储在数组中的信息,将其发送到数据库。

我遍历数组,并将信息保存在我发送到数据库的每个位置,每个位置都有一个 http 帖子

问题是,和http post发送信息的时间不同,比如数组的第一个位置是80ms发送的,第二个是20ms发送的

因此,信息未按正确顺序存储。因为首先他在数字 1 之前得到了数字 2。

这是我的代码

$scope.sendlimits = function (){
var namelimit= document.getElementById('name').value;
var idmap= document.getElementById('map_id').value;

if($scope.numberofpoints==0 || $scope.numberofpoints==null || namelimit==null || namelimit==""){
    swal({
        title: "Error",
        text: "You must enter all the map data.",
        icon: "error"
    })
}else{
    for(var i=0; i<$scope.numberofpoints; i++){

        var latitudedb= $scope.arraycoordinates[i].lat;
        var longitudedb=  $scope.arraycoordinates[i].lng;
        var namelimitdb= namelimit+i;

        $http.post("/territoriosinteligentes/sendlimits", {name: namelimitdb, latitude: latitudedb,
            longitude: longitudbd, identificador: namelimit, map_id: idmap}).then(function(response)
        {

            $scope.status = response.status;
            $scope.data = response.data;
            swal({title: "Loading Limits",text: "Please Wait.",icon: "success"})

        },

        function(response) {
            $scope.data = response.data || 'Request failed';
            $scope.status = response.status;
            swal({
                title: "Error",
                text: "It was not possible to register the limits, you must enter all the data",
                icon: "error"
            })
        })
    }
}

}

这是发生的事情的一个例子在此处输入图像描述

4

0 回答 0