下载请求完成后调用功能

发布于 2025-02-13 11:34:47 字数 614 浏览 0 评论 0原文

目前,我正在尝试在请求完成后执行此回电功能,因此我能够关闭

function handleDownloadFinished(): void{
setDownloadingActivity(false);}

我希望此代码在此之后运行的模式:

public static async exportData(id: number, _callback: Function): Promise<void> {
const queryString = stringifyQuery(
  {
    token: BaseAPI.getJwt(),
  },
  {
    arrayFormat: "bracket",
  }
);
const anchorElement = document.createElement("a");
anchorElement.download = "file.xlsx";
anchorElement.href = `URL`;
anchorElement.click();
_callback();}

不幸的是,它同时运行两个功能,然后动画不运行。有时候,我可以进行动画运行,但不停。现在,要使它起作用,该应用程序依靠用户输入来阻止其运行。

I'm currently trying to get execute this call back function after the request is finished, so I'm able to close the modal where

function handleDownloadFinished(): void{
setDownloadingActivity(false);}

I want this code to run after this:

public static async exportData(id: number, _callback: Function): Promise<void> {
const queryString = stringifyQuery(
  {
    token: BaseAPI.getJwt(),
  },
  {
    arrayFormat: "bracket",
  }
);
const anchorElement = document.createElement("a");
anchorElement.download = "file.xlsx";
anchorElement.href = `URL`;
anchorElement.click();
_callback();}

Unfortunately, It runs both functions at the same time, and then the animation does not run. Some times, I'm able to make the animation run, but not stop. Right now, to have It working, the application relies on user input to stop it running.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仅冇旳回忆 2025-02-20 11:34:47

浏览器不会以任何方式将下载文件的进度传达给网页。因此,您的代码无法知道何时下载完成。

您只需要考虑到这个事实,就必须设计您的UI。

The browser does not communicate the progress of downloaded files to a webpage in any way. So you code cannot know when a download has finished.

You're just going to have to design your UI with this fact in mind.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文