我有以下脚本:
posting();
pause(time);
postSent(postUrl, fields);
function postSent(postUrl, fields)
{
$.ajax( {
url : postUrl,
type : "POST",
data : fields,
cache : false,
error : function(xhr, textStatus, errorThrown) {
var answer = xhr.responseText;
answer = answer.split(":");
answer = answer[0].replace(/}/g,"").replace(/{/g,"").replace(/"/g,"");
if (answer == "id")
{
isPostSent = true;
}
else
{
isPostSent = false;
}
}
});
}
function pause(milliseconds) {
var dt = new Date();
while ((new Date()) - dt <= milliseconds) { /* Do nothing */ }
}
function posting()
{
var table = '';
table += '<table border="0" rules="none" cellpadding="5" style="z-index:+10; position:fixed; top:35%; left:35%; box-shadow: 0px 0px 5px 5px #888888;" rules="none" border="0" bgcolor="#edeff4">';
table += '<td align="center">';
table += '<img src="images/loading.gif" id="post_status_image">';
table += '</td>';
table += '<tr >';
table += '<td align="center">שולח הודעה, אנא המתן...</td>';
table += '</tr>';
table += '<tr>';
table += '<td align="center" id="post_status"></td>';
table += '</tr>';
table += '<tr >';
table += '<td align="center" ><img id="post_close" src="images/close1.png" onclick="closePop()" style="visibility:hidden;"></td>';
table += '</tr>';
table += '</table>';
document.getElementById('post').innerHTML = table;
}
时间设置为 3000 毫秒。我的问题是我想在屏幕上显示表格(它是一种“加载”屏幕),然后暂停脚本。实际上,由于某种原因,脚本首先暂停,只有在它完成后,它才会向我显示加载屏幕......怎么会?