在我的项目中,我使用Setinterval来显示Excel数据库的导入状态。 即,如果excelsheet包含100条记录意味着我的状态消息, 行1个0F 100插入的行 行2 100的插入的行..如何在javascript中使用setinterval来显示导入任务的状态?
但是,如果行包含任何空值意味着我需要得到错误详细信息并在状态消息中添加。所以它适用于一些问题。
我的javascript功能如下。
function ImportFormSuccess(taskId) {
endform();
Tid = taskId;
try {
intervalId = setInterval(function() {
$.ajax(
{
type: "POST",
url: rootDir + "Import/Progress",
data: { id: Tid },
success: function (data) {
if (data.split(',').length > 1) {
ErrorMessage = ErrorMessage + data.split(',')[1] + "<br/>";
updateMonitor();
}
else {
Message = data;
updateStatus();
}
}
});
}, 100);
}
catch (err) {
txt = "Error Description" + err.Message + "</br>";
txt += "Click Ok to Continue. . .";
alert(txt);
}
function updateMonitor() {
$('#monitors').attr("class", "");
$("#monitors").html(Message + "<br/>" + ErrorMessage);
}
function updateStatus() {
$('#status').attr("class", "");
$("#status").html(Message);
}
查看代码是:
<div id="monitors" style="padding: 2px;width:500px;height:150px;overflow:auto;border:1px solid;></div>
如果我运行该项目,并开始导入手段, 它显示以下内容:
Row 5 Insert Failed. Row Contains Empty Value
Row 5 Insert Failed. Row Contains Empty Value
Row 5 Insert Failed. Row Contains Empty Value
Row 5 Insert Failed. Row Contains Empty Value
Row 7 Insert Failed. Row Contains Empty Value
Row 7 Insert Failed. Row Contains Empty Value
Row 7 Insert Failed. Row Contains Empty Value
Row 7 Insert Failed. Row Contains Empty Value
Row 10 Insert Failed. Row Contains Empty Value
Row 10 Insert Failed. Row Contains Empty Value
Row 10 Insert Failed. Row Contains Empty Value
Row 10 Insert Failed. Row Contains Empty Value
Row 15 Insert Failed. Row Contains Empty Value
Row 15 Insert Failed. Row Contains Empty Value
Row 15 Insert Failed. Row Contains Empty Value
但我需要它只能打印一次.. 即,
Row 5 Insert Failed. Row Contains Empty Value
Row 7 Insert Failed. Row Contains Empty Value
Row 10 Insert Failed. Row Contains Empty Value
Row 15 Insert Failed. Row Contains Empty Value
任何帮助?
你可以使用正则表达式.match(/ \((? - \ d +)\)/)仅从您的消息中提取数字并将其分配给全局变量。所以在打印这个$(“#status”).html(Message)之前,你可以使用指定的全局变量来验证它是否与以前一样。如果不匹配,则打印,否则返回false。 –
100ms是否可能太快,并且您仍在处理同一行时正在使用该服务? – Tallmaris
@Tallmaris 100ms只是一个假设..但它取决于行的长度和数据..这就是为什么它stucked .. –