原来的问题似乎有两个问题: 1)睡眠函数没有正确地模拟长时间运行的操作,如HTML请求。2) IE,至少v8和v9似乎没有像火狐那样正确地更新他们的显示。有没有人知道强制IE处理UI更新的方法?下面的代码在Firefox上运行得很好,但IE直到最后才更新运行计数的显示,除非我插入一个强制暂停的警报。如果有50个项目,批处理大小为10,我希望显示运行计数的HTML显示10,20,30,40,50。在IE中,它会从10跳到50,而Firefox会正确更新。
while (done == false) {
var url = 'myLongRunningOperation.com/doSomething.html&LastID='+lastPriorIndex;
$.ajax({
type: 'GET',
url: url,
dataType: 'json',
success: function(data) {
soFar += data.Succeeded + data.Failed;
$('#numCompleted').val(soFar).show();
LastPriorIndex= data.LastID;
if (soFar >= totalNumberOFDocs) {
done = true;
}
},
data: {},
async: false
});
}我正在尝试使用JQuery UI模式对话框作为状态对话框。首先,它应该显示更新消息,然后在长时间运行的操作完成并添加到HTML时处理更新消息。但是,该对话框直到最后才会显示,然后显示所有消息。如果我在显示对话框后发出警告,它将会显示,但在所有操作完成后会立即显示更新所有消息。我希望我所需要的只是某种类型的check- the -message-queue函数来让它更新,因为警告会导致对话框显示。或者,这可能是我模拟日志运行操作的方法,这就是模拟睡眠的问题。
$(function() {
$("#dialog2").dialog({
bgiframe: false
,height: 140
,modal: true
,autoOpen: false
});
});
function TestModalUpdate2() {
$('#dialog2').dialog("open");
//alert('foo'); //if this alert is present the dialog shows before the doSomething calls execute but wont update till all of them are done
$('#dialog2').show();
var i
for(i = 0; i < 5; i++) {
doSomething($('#dialog2'));
$('#dialog2').show();
}
}
function doSomething(obj1) {
wait(1000);
obj1.html(obj1.html()+"<p>new line</p>")
//alert('this will also cause the dialog to update in between doSomethings')
}
function wait(msecs) {
var start = new Date().getTime();
var cur = start
while(cur - start < msecs) {
cur = new Date().getTime();
}
}
<input type="button" id="Test2" onclick="TestModalUpdate2();" value="Test2"/>发布于 2012-05-03 02:56:22
在进一步研究表明在同步模式下操作可能会很麻烦之后,我将其转换为一个可以工作的递归版本。
function processBatch() {
var url = 'DoSomethingLongRunning.html&StartingIndex='+startingIndex+'&BatchSize='+batchSize;
$.getJSON(url
,function(data) {
soFar1 += data.Succeeded + data.Failed;
$('#numCompleted').val(soFar1).show();
startingIndex = data.LastID;
if (soFar1 < totalNumberOfDocs) {
processBatch();
}
}
);
}发布于 2012-04-26 13:20:44
除此之外,我也有同样的问题,但我也在使用jqgrid,并使用jqgrid saveRow函数。我认为这可能是导致问题的原因,但不是100%确定。
它甚至在我的对话框中阻止了动画gif的渲染,所以至少可以说它很有趣:)
我正在做类似这样的事情
$("#WOTaskList").jqGrid('saveRow', rowArray[rowIndex], onSave, null, null, null, onSaveError)
在我的onSave中
$(".waitUIText").html("<span>Saved " + nSavedRows + " of " + nEditeddRows + "</span>");
还有..。现在我已经弄清楚了..。默认情况下,jqgrid syncronous会阻止save调用:/
已将ajaxRowOptions:{ async: true }添加到jqgrid默认初始化,对话框正在按预期更新..
https://stackoverflow.com/questions/10323711
复制相似问题