之后,服务器重定向到下载文件捕获重载/ endrequest事件 [英] Capture reload/endrequest event after server redirect to download file

查看:105
本文介绍了之后,服务器重定向到下载文件捕获重载/ endrequest事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个网页我有一个Excel下载按钮时会被重定向到该服务通过应用程序/ MS-Excel中 MIME类型,这通常会导致所要求的Excel文件网页在浏览器的文件下载。

Inside a webpage I have an Excel download button, which redirects to a webpage that serves the requested Excel file via the application/ms-excel MIME type, which usually results in a file download in the browser.

在网页中,我有以下的jQuery code:

In the webpage, I have the following jQuery code:

$(document).ready(function () {
    $(".div-export .button").click(function () { setBusy(true); });
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function () { 
        setBusy(false);
    });
});

在用户等待的Excel文件送达它显示一个繁忙的动画。

Which displays a busy animation while the user waits for the Excel file to be served.

问题是:动画没有结束( setBusy(假); )的文件下载后,因为 endRequest 事件不会被解雇可能是因为服务器重定向。

Problem is: The animation doesn't end (setBusy(false);) after the file download, because the endRequest event doesn't get fired, probably because of the server redirect.

有没有人有办法解决这个?

Does anyone have a workaround for this?

修改:下载按钮被处理的的UpdatePanel

Edit: The download button is handled in an UpdatePanel.

推荐答案

而不是使用服务器重定向,我已经决定使用后,鼠标光标复位被触发一个JavaScript文件重定向。要做到这一点,我已经包括持有的URL隐藏字段:

Instead of using a server redirect, I've decided to use a javascript document redirect that is triggered after the mouse cursor is reset. To do this, I've included a hidden field that holds the url:

<asp:HiddenField id="hidExportUrl" runat="server" EnableViewState="false" />

这是由客户端处理 END_REQUEST 处理程序:

$(document).ready(function () {
    $(".div-export .button").click(function () { setBusy(true); });

    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function () { 
        setBusy(false);

        var url = $("[id$='hidExportUrl']").val();

        if (url && url != "") {
            $("[id$='hidExportUrl']").val("");
            window.location = url;
        }
    });
});

这篇关于之后,服务器重定向到下载文件捕获重载/ endrequest事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆