62,047
社区成员
发帖
与我相关
我的任务
分享
var timer;
var threadKey = Math.random().toString().replace("0.", "");//当前进程标识
//下面是查询执行进程的函数
function checkProgress() {
$.ajax({
type: "post",
url: "../../tools/data_copy.ashx?act=check_progress",
dataType: "json",
data: "threadKey=" + threadKey,
success: function (data) {
alert(data.msg);
if (data.msg == "1") {
$(".msg").html(data.msgbox);
}
},
error: function (data, status, e) { }
});
}
//每隔500毫秒查询一次执行状态
timer = setInterval("checkProgress()", 500)
$(function () {
var idlist = "<%=idlist %>";
//AJAX执行一个线程,该线程可能会耗时比较长,因此在执行过程中每隔500毫秒用checkProgress()函数查询一次执行进度,但经检测每次都要等这整个进程结束后checkProgress()才开始执行,是不是因为jquery的ajax模块不支持多线程并发呢?
$.ajax({
type: "post",
url: "../../tools/data_copy.ashx?act=copy_category&threadKey=" + threadKey,
dataType: "json",
data: "idlist=<%=idlist %>&random=" + Math.random(),
success: function (data) {
clearInterval(timer);
},
error: function (data, status, e) {
clearInterval(timer);
$(".msg").append("<br /><font color='red'>× 执行中出错,执行终止</fong>");
}
})
})