首页 > 解决方案 > 使用 post 方法更新循环的进度条

问题描述

我有一个来自数组的循环,它的作用是在将其保存在数据表中之前,它将检查该项目是否存在于数据库中,这是代码

for (i = 0, len = array.length; i < len; i++) {
  var item_code   = array[i][1];
  var description = array[i][2];
  var qty         = array[i][0];

  if (item_code != "") {
    console.log(item_code);
    var if_exsist = function () {
      var tmp = null;
        $.ajax({
        url: "../program_assets/php/web/stocks_excel_insert_transactions.php",
        data: {
          saving_mode   : 'check_item',
          item_code     : item_code
        },
        'async': false,
        type: 'post',
        success: function (data) {
          var data = data.trim();
          if (data == 0) {
            tmp = "no"
            $('#btn_save').prop('disabled', true);
          } else {
            tmp = "yes"
          }
        }
      });
      return tmp;
    }();
    
    tbl_delivery_list.row.add({
      "docket_number" : docket_number,
      "from"          : from,
      "from_id"       : from_id,
      "to"            : to,
      "to_id"         : to_id,
      "item_code"     : item_code,
      "description"   : description,
      "qty"           : comma(qty),
      "exsist"        : if_exsist
    }).draw( false );
    
    counter++;
  }
}

上面的代码可以工作,但我的问题是如何合并进度条?加载样本。我添加了这段代码,但加载是在所有工作完成后发生的。

progress = counter / array.length;
progress = progress * 100;
$(".bar").css("width", progress + "%");

我这里的目标是在第一次写完代码后,一一更新进度条

标签: javascripthtmljquery

解决方案


推荐阅读