JQuery按照form下载文件+后台asp.net,非ajax(下)
来源:互联网 发布:levis和lee知乎 编辑:程序博客网 时间:2024/05/22 00:35
前面说到通过js form方式POST数据,那后台应该怎么处理了。
因为这代码的框架是一个外包写的,写的很复杂,可能也是之前所有的系统的合集。
暂时也没有时间去整理,所以只是在原有方式上增加功能。
作为一个C++的工程师,现在去搞前端。。。。
后台有两种办法处理,一般的方式是先生成本地文件,然后在发送,还有就是直接发送数据。
我目前采用的是先生成本地文件。
看看代码吧
var filename = "withdraw_"+DateTime.Today.ToString("yyyyMMddhhmmss") + ".csv"; var path = "~/ApiViews/PXMServer/" + filename; var filePathName = System.Web.HttpContext.Current.Server.MapPath(path); ExportWithdraw(context, filePathName); FileInfo fileInfo = new FileInfo(filePathName); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ClearContent(); HttpContext.Current.Response.ClearHeaders(); HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + filename); HttpContext.Current.Response.AddHeader("Content-Length", fileInfo.Length.ToString()); HttpContext.Current.Response.AddHeader("Content-Transfer-Encoding", "binary"); HttpContext.Current.Response.ContentType = "application/octet-stream"; HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312"); HttpContext.Current.Response.WriteFile(fileInfo.FullName); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.End();
其他的函数可以忽略,最重要的是response的处理。
这样就完成了前后端的交互。
0 0
- JQuery按照form下载文件+后台asp.net,非ajax(下)
- JQuery按照form下载文件+后台asp.net,非ajax(上)
- JQuery按照form上传文件+asp.net后台处理(一)
- JQuery按照form上传文件+asp.net后台处理(二)
- JQuery按照form上传文件+asp.net后台处理(三)
- jquery ajax调用asp.net 后台方法
- JQuery Ajax调用asp.net后台方法
- jQuery.ajax()调用asp.net后台方法
- JQuery Ajax调用asp.net后台方法
- JQuery Ajax调用asp.net后台方法
- JQuery Ajax调用asp.net后台方法
- ASP.NET中JQuery+AJAX调用后台
- jQuery.ajax()调用asp.net后台方法
- jQuery.ajax()调用asp.net后台方法
- jQuery.ajax()调用asp.net后台方法
- .net+ajax+jquery.form
- JQuery Form Ajax提交asp.net表单时失败
- ASP.NET web form 使用jQuery ajax 省市级联
- 简化的以,号分隔为SQLtable
- rapidjson使用总结
- html网页框架
- 统计学习方法 --- 感知机模型原理及c++实现
- 背包问题九讲
- JQuery按照form下载文件+后台asp.net,非ajax(下)
- Ubuntu下Matlab 2014 快捷键修改
- Week3-6NLP task 2/3
- Android Context 详解
- delphi实现托盘
- 快速判断恶意代码是否有异或加密算法
- redis配置认证密码
- 【Leet Code】238. Product of Array Except Self---Medium
- Android酷炫实用的开源框架(UI框架)