web 下载导出文件

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/LeehomeYU/article/details/81186875

总体逻辑还是文件保存在服务器,然后下载连接服务器所在位置,下载导出。

后台:

   string Weburl = _request.ApplicationPath + TmepUrl + fileName + ".xls";
   OutputContent(true, Weburl);

   protected void OutputContent(bool result, string content)
        {
            content = content.Replace("\r", "").Replace("\n", "");
            if (result)
                content = "{\"result\":true,\"data\":\"" + content + "\"}";
            else
                content = "{\"result\":false,\"data\":\"" + content + "\"}";
            _context.Response.Write(content);
        }

前台:

 $.ajax({
        type: "POST",
        url: url1,
        data: queryParx,
        dataType: "json",
        error: function (xmlHttpRequest, textStatus, errorThrown) {
            $.tipMessage('错误', errorThrown, 'error');
        },
        success: function (returnJsonValue) {
            if (returnJsonValue.result) //如果结果是有数据的
                    {
                var iframe = "<iframe height='0' width='0' src='" + returnJsonValue.data + "'></iframe>";
                        $("body").append(iframe);
                    }
                    else
                $.tipMessage('信息', returnJsonValue.data, 'info'); //弹出消息
        },
        beforeSend: function () {
        },
        complete: function () {
        }
    });

猜你喜欢

转载自blog.csdn.net/LeehomeYU/article/details/81186875