当前位置:编程学习 > C#/ASP.NET >>

ajax+jquery+NPOI导不出数据,在线等。。。

页面上导出按钮点击是触发的javascript方法:

function ExportData() {
          $.ajax({
              type: "post",
              url: "../_Ajax/AjaxCountBase1.ashx",
              data: 'op=Export',
              dataType: "text",
              cache: false,
              success: function () {
                  
              },
              error: function (message) {
                  LG.showError(message);
                  //$.ligerDialog.tip({ title: '提示信息', content: '导出失败' });
              }
            });
      }

AjaxCountBase1.ashx里调用的方法:

protected void ExportExcel(HttpContext context)
        {
            if (ExportDataTable != null)
            {
                ExcelRender.RenderToExcel(
                ExportDataTable,
                context,
                "统计.xls");
            }
        }

点导出后所有代码都正常运行 ExportDataTable 也是有数据的 但就是没反应 没有弹出要保存Excel的提示 --------------------编程问答-------------------- 这样应该不行的吧,弹出文件对话框是浏览器控制的,得让浏览器知道有文件要下载啊。
我是用新建一个隐藏的frame的方式实现的 --------------------编程问答--------------------
引用 1 楼  的回复:
这样应该不行的吧,弹出文件对话框是浏览器控制的,得让浏览器知道有文件要下载啊。
我是用新建一个隐藏的frame的方式实现的

请问具体怎样实现啊 --------------------编程问答--------------------

var downloadFrame;

function Download(src) {
    // Check to be sure this async postback is actually 
    //   requesting the file download.

    if (!downloadFrame) {
        downloadFrame = document.createElement("iframe");

        // Add the IFRAME to the page.  This will trigger
        //   a request to GenerateFile now.
        document.body.appendChild(downloadFrame);

        // This makes the IFRAME invisible to the user.
        downloadFrame.style.display = "none";
    }

    // Point the IFRAME to GenerateFile, with the
    //   desired region as a querystring argument.
    downloadFrame.src = src;

    setTimeout("downloadFrame.src=''", 3000);
}
--------------------编程问答--------------------
引用 3 楼 danjiewu 的回复:
JavaScript code
?



123456789101112131415161718192021222324

var downloadFrame;   function Download(src) {     // Check to be sure this async postback is actually      //   requesting the file……


怎么用啊?
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,