file Download 監聽文件下載完成狀態

下載 fileDonwload.js

https://www.bootcdn.cn/jquery.fileDownload/

頁面中使用

            var url = '@Url.Action("ExcelExportDashboard", "KPITable")';
            var dat = { month: month, dataType: valueType };
            var data = dat;
            $.fileDownload(url, {
                httpMethod: 'GET',
                data: data,
                prepareCallback: function (url) {
                    $("#downloadingID").removeClass("glyphicon-download-alt excel-download2").addClass("clickstate excel-download_Loading");
                },
                successCallback: function (url) {
                    $("#downloadingID").removeClass("clickstate excel-download_Loading").addClass("glyphicon-download-alt excel-download2");
                },
                failCallback: function (html, url) {
                    // 相關業務代碼--這裏引入了layer
                    alert("下載失敗");
                }
            });

後臺

  HttpCookie aCookie = new HttpCookie("fileDownload", "true");
            aCookie.Path = "/";
            aCookie.Expires = DateTime.Now.AddDays(1);
            Response.Cookies.Add(aCookie);
    return File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", Server.UrlEncode(fileName));
  }

 

 

參考:

https://blog.csdn.net/qq_35477390/article/details/126045725

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章