zoukankan      html  css  js  c++  java
  • jQuery以Post方式发送请求并获取返回的文件供下载!

    用ajax请求文件下载当然是可以的,不用有返回值,代码差不多是这样:

    try
            {
                string FileName = ".//doc//[大家网]Beginning.ASP.NET.2.0.E-Commerce.in.C#.2005.From.Novice.to.Professional[www.TopSage.com].pdf";
                FileName = ".//doc//Shipping+Advice+Spec++V1.4.xls";
                FullFileName = Server.MapPath(FileName); 
                //FileName--要下载的文件名 
                FileInfo DownloadFile = new FileInfo(FullFileName);
                if (DownloadFile.Exists)
                {
                    Response.Clear();
                    Response.ClearHeaders();
                    Response.Buffer = false;
                    Response.ContentType = "application/octet-stream";
                    Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.ASCII));
                    Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
                    Response.WriteFile(DownloadFile.FullName);
                    Response.Flush();
                    Response.End();
                }
                else
                {
                    //文件不存在
                }
            }
            catch
            {
               //打开时异常了
            }
    View Code
  • 相关阅读:
    drf 三大认证详解
    管理表页面的创建
    电脑自动关机设置
    jwt 认证规则
    视图家族练习
    JQuery 数组获取和删除元素
    JQurey 添加和删除元素
    Java 占位符
    Redis
    线程
  • 原文地址:https://www.cnblogs.com/marslin/p/3138729.html
Copyright © 2011-2022 走看看