如何在加载页面的同时等待长时间的处理方法完成

How to put a loading page while waiting for the long-time processing method completes

本文关键字:长时间 等待 处理 方法 加载      更新时间:2023-09-26

aspx文件中的代码如下:

<script type="text/javascript">
function loadimg() {            
    window.location.href = "../OutputHtml/loading.html";
    return true;
}
</script>
<asp:ImageButton title="fetch matrix" ImageUrl="~/Images/matrix.png" ID="btnRouteMatrix" OnClientClick="return loadimg();" runat="server" OnClick="btn_RouteMatrix" />

点击ImageButton后,对应的页面没有任何变化。诀窍是当我改变window.location。Href " to "parent.window.location。

function loadimg() {            
    parent.window.location.href = "../OutputHtml/loading.html";
}

父页(即整个页面)立即更改。这有什么不对。是否还有其他方法让我在btn_routemmatrix方法完成之前将加载页面放在工作框架中?

哇,撑着点。

你不需要加载一个完全独立的页面来显示加载图标。
一个建议是在你的页面上有一个图片指向你的加载图标,并隐藏它。

然后,当你调用你的方法时,让它做的第一件事就是显示它,然后在处理完成后隐藏它。

例子:

<img id="loader" alt="loader" src="../Images/Loader.gif" style="display:none" />
<button type="button" onclick="runMethod()">Click Me</button>
<script type="text/javascript">
   function runMethod(){
     $("#loader").show();

     // Long running method

     $("#loader").hide();
   }
</script>