我正在开发一个需要与Internet Explorer 8兼容的Web应用程序(您知道,与 HELL 兼容)。问题是我上传的文件后来由PHP代码处理并刷新页面。当我有一个已处理的文件时,我使用该文件将数据插入表中,因此在插入此数据时需要一个处理栏和块UI(我需要为每一行调用另一个PHP进程)
问题是下一个,我想阻止那个UI,我有逻辑和所有兼容性问题解决了;但经过5天的工作,我无法阻止用户界面。这是一个最小代码(它封装了我们需要的所有代码),以简化这个想法:
$(document).ready({
(...)
$("#title").html('some text');
$("#bar").html('');
$.blockUI({message: $('#window'),css:{width:'303px'}});
go = true;
while (go){
$.ajax({<ASYNC FALSE AJAX CALL});
if (!file.lines) go = false;
<update progress>
}
$.unblockUI();
(...)
});
显然, $。blockUI 应该阻止主线程(直到我取消阻塞)并显示一个个性化窗口,其下一个代码是:
<div id="window" style="display: none; cursor: default">
<div id="title_bar">
<div id="titulos">some text</div>
<div id="cerrar"></div>
</div>
<div id="body">
<img src="an icon"
alt="enviando" border="0" width="33" height="33" id="enviar">
<p class="titulo" id='title'></p>
<p class="texto" id='bar'></p>
<br />
</div>
</div>
我认为问题是我在一个不是主线程的线程上执行该块,并且我无法阻止UI;但是我需要那个块,因为我必须强迫用户等到我处理所有信息。
谢天谢地,我希望你能帮助我。
答案 0 :(得分:1)
我认为主要是因为同步,但如果你使它异步,你需要在代码中进行更改。删除while循环并调用一个函数,它将进行异步调用,并在成功完成时递归调用相同的函数。满足终端条件后,取消阻止用户界面,如下所示:
$.blockUI({message: $('#window'),css:{width:'303px'}});
// based on the above code I assume you will get file as a response.
process();
function process(file){
if (file && !file.lines){
$.unblockUI();
}
$.ajax({<ASYNC TRUE AJAX CALL})
.done(function(file){
<update progress>
process(file);
});
}