在我的项目中,我使用 Setinterval 来显示 excelsheet 到数据库的导入状态。即,如果 excelsheet 包含 100 条记录意味着我的状态消息是,第 1 行 0f 100 行已插入第 2 行,共 100 行已插入。
但是,如果该行包含任何空值意味着我需要获取错误详细信息并将其添加到状态消息中。所以它适用于一些问题。
我的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
有什么帮助吗???