ajax - 为什么 GIF 动画在执行 AJAX 调用时停止工作?

我的目标是在执行 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 以保持动画继续。

https://stackoverflow.com/questions/11453277/

相关文章:

asp.net-mvc-3 - 如何修复来自 Shibboleth 的 SAML SSO 后的浏览器

asp.net - 转移到服务器场中的不同服务器时,IsPostBack 为假?

asp.net - 为什么 GetServerVariable ("HTTP_URL") 根据管道模

symfony - doctrine2 ifnull

ruby-on-rails-3 - Rails 应用程序占用所有服务器内存

wordpress - 更改站点 URL 后无法访问 Wordpress wp-admin

php - 递归菜单树函数

ios - 我的 iOS 开发者证书或私钥在 git 中吗?

scala - 如何将 request.body 转换为字节数组以计算 MD5?

ruby-on-rails-3.1 - Rack 中间件如何重定向到我的 Rails 应用程序中的