javascript - 使用 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 + "%");
我这里的目标是在第一次写完代码后,一一更新进度条
解决方案
推荐阅读
- rss - Automatic mediawiki article generation with a script?
- amazon-s3 - Prevent httpclient from adding server url when calling presigned url
- javascript - Getting ↵ in my array while Getting data from td cells
- python - 假设我有一个清单。lst[0] 和 [lst[0]] 有什么区别?
- oracle - 查找日期相互重叠的记录
- apache-kafka - 使用 Kafka-MongoDB-Connect 将数据插入 MongoDB
- jquery - 在滚动条上隐藏 div
- chart.js - 如何减少任何图表中的边框宽度?
- reactjs - Is OnChange required for react forms anymore?
- java - 使用 java API 问题创建图片库