我的目标是在执行 AJAX 调用时显示加载弹出窗口(其中包含 GIF)。 我正在使用 jQuery UI Modal dialog ,其中我使用 CSS 插入 GIF 动画。在 AJAX 调用开始之前,我打开对话框并在调用完成后立即关闭它。问题是当 AJAX 调用运行时 GIF 停止工作并且它发生在所有浏览器中。我正在使用以下代码:
<div id="loadingScreen" title="Loading">Please wait...</div>
#loadingScreen {
background: url(http://regretless.com/stuff/jQuery/images/loading.gif) no-repeat 5px 8px;
padding-left: 25px;
}
$("#loadingScreen").dialog('open');
setTimeout(function () {
$.ajax({
type: "GET",
url: "testing.txt",
async: true,
dataType: "text",
success: function (returnText) {
$("#viewDescription").text(returnText);
$("#viewGroupID").text(" " + t.id);
$("#loadingScreen").dialog('close');
$('#View').dialog('open');
},
error: function (xhr, status, error) {
$("#loadingScreen").dialog('close');
alert("An error has occured");
}
});
}, 10);
谁能告诉我可能是什么问题?
最佳答案
因为这是背景,所以您需要将焦点设置到#loadingScreen 以保持动画继续。
关于ajax - 为什么 GIF 动画在执行 AJAX 调用时停止工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11453277/