简体   繁体   English

如何知道请求文件完成?

[英]how to know request file completed?

I have some code like this. 我有一些这样的代码。

function ExportToExcel() {
    showLoading();
    window.location.href = "/UI/WorkingTime/CreateFile.aspx?Type=1";
     // I want hide loading here
    //window.hideLoading();
};

How can I hide loading after create file completed? 创建文件完成后如何隐藏加载? How can I detect that created file completed? 如何检测创建的​​文件是否完成?

This line: 这行:

 window.location.href = "/UI/WorkingTime/CreateFile.aspx?Type=1"; 

will completely tear down the page and the JavaScript environment associated with it, and replace it with a new page and associated JavaScript environment containing the response from the server. 将完全拆除该页面和与其关联的JavaScript环境,并用包含服务器响应的页面和关联的JavaScript环境替换它。 So you can't do window.hideLoading(); 所以你不能做window.hideLoading(); as that function, and the environment it was in, have been discarded to make room for the new environment of the new page. 作为该功能及其所处的环境已被丢弃,以便为新页面的新环境腾出空间。

If you don't need the response from that URL displayed in the current page, you can retrieve it via ajax ( fetch , XMLHttpRequest ), or use an iframe instead, and then you could use code in the page being loaded to tell its parent window that it was loaded, so that the parent window could hide the loading indicator. 如果不需要当前页面中显示的URL的响应,则可以通过ajax( fetchXMLHttpRequest )检索它,或者使用iframe代替,然后可以使用正在加载的页面中的代码来告诉其父对象加载窗口,以便父窗口可以隐藏加载指示器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM