liyb5619
微醺_zZ
2015-04-15 03:16

ajax异步调用一般处理程序实现下载不弹出保存提示

  • 一般处理程序
  • ajax

前端js代码:

 function QueryExcel() {
            var data = Ext.getCmp("frmMain").GetValues();// 获取json数据
            Ext.Ajax.request({
                url: '../Services/ReportExportHandler.ashx', // Webservice的地址以及方法名  
                jsonData: data,
                method: 'POST' ,// poste 方式传递
                //success: function (result) {
                //},
                //failure: function (result) {
                //}
            });
        }

            一般处理程序代码:
                  string fileName = HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes("111.csv"));
            //string fileName = HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes(dto.Name + ".csv"));
            context.Server.ScriptTimeout = 600;
            context.Response.ContentType = "application/octet-stream";
            context.Response.Charset = "gb2312";
            context.Response.AddHeader("Content-Disposition", string.Format("attachment;filename=\"{0}\"", fileName));
            context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");

            DataTable dt = this.GetReportExcuteData(dto, paramsValues).Tables[0];
          byte[] bs =  ExportHelper.GetMemoryBytes(dt);

          context.Response.BinaryWrite(bs);
                      context.Response.End();
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答