javascript - 显示加载程序直到整个页面在 asp.net 中完全加载

标签 javascript jquery asp.net

我有 gridview,其中有 700 行。我已将 ajax 加载器放在页面上,如 link 所示。 。当还有 2-3 分钟完全加载数据时,加载程序消失。我想显示加载程序直到页面完全加载。我怎样才能实现这个目标?

<script type="text/javascript">
              function ShowProgress() {

                  setTimeout(function () {
                      var modal = $('<div />');
                      modal.addClass("modal");
                      $('body').append(modal);
                      var loading = $(".loading");
                      loading.show();
                      var top = Math.max($(window).height() / 2 - loading[0].offsetHeight / 2, 0);
                      var left = Math.max($(window).width() / 2 - loading[0].offsetWidth / 2, 0);
                      loading.css({ top: top, left: left });
                  }, 1000);
              }

              $(document).ready(function () {
                  $('#Button1').click(function () {
                      ShowProgress();
                  });
              });
          </script>
<style type="text/css">
    .modal
    {
        position: fixed;
        top: 0;
        left: 0;
        background-color: black;
        z-index: 99;
        opacity: 0.8;
        filter: alpha(opacity=80);
        -moz-opacity: 0.8;
        min-height: 100%;
        width: 100%;
    }

    .loading
    {
        font-family: Arial;
        font-size: 10pt;
        border: 5px solid #67CFF5;
        width: 200px;
        height: 100px;
        display: none;
        position: fixed;
        background-color: White;
        z-index: 999;
    }

</style>
<div class="loading" align="center">
    Loading. Please wait.<br />
    <br />
    <img src="loader.gif" alt="" />

</div>

最佳答案

在发送ajax请求之前调用加载器函数,并在收到响应后隐藏加载器,或者在您的情况下数据绑定(bind)到gridview。

displayLoader();
    $.ajax({
        type: "POST",
        contentType: "application/json",
        url: url
    }).done(function (data) {
        //call is successful
        hideLoader();
    }).fail(function () {
        //call has failed
        hideLoader();
    }).always(function () {
        //always execute despite failure/success
        hideLoader();
    });

关于javascript - 显示加载程序直到整个页面在 asp.net 中完全加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44314324/

相关文章:

javascript - javascript中的数组搜索

javascript - 使用 php 生成的表中的可选行

php - Jquery 添加值以选择选项

c# - 以编程方式发送 Salesforce Web 至潜在客户表单数据

ASP.NET 按钮单击事件在 IE 中不起作用

javascript - 您如何使用 Javascript 查看 Firebase 数据库中是否存在目录而不覆盖数据?

javascript - 直到我开始过滤才显示数据?

jquery - jquery lavalamp 菜单上的中心图像

javascript - 切换 Material 设计图标

asp.net - 如何向 Web 方法传递参数?