当我尝试使用回发以下代码时,文件下载正常进行:
FileInfo file = new FileInfo("C:\\a.txt");
Response.ClearContent();
Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "text/plain";
Response.TransmitFile(file.FullName);
Response.End();
但是,如果我将上述代码放在公共静态 Web 方法中并使用 AJAX 调用它,我会收到错误消息,例如“进程被中止”。(当然要获得当前响应,我会写 HttpContext.Current.Response)这让我想到这两种反应的性质是不同的。我的问题是,如果它们不同,那么到底有什么不同?有没有办法用 AJAX 实现同样的目标?