在本文中,我们将详细介绍ExtjsAjax文件下载请求C#MVC的各个方面,并为您提供关于ajaxfileuploadexcel的相关解答,同时,我们也将为您带来关于ajax请求文件下载、Ajax文件
在本文中,我们将详细介绍Extjs Ajax文件下载请求C#MVC的各个方面,并为您提供关于ajaxfileupload excel的相关解答,同时,我们也将为您带来关于ajax 请求 文件下载、Ajax文件下载、Ajax文件下载使用Jquery,PHP、Ajax文件下载问题的有用知识。
本文目录一览:Extjs Ajax文件下载请求C#MVC(ajaxfileupload excel)
我发送这个ajax请求并从服务器端获取它.
EXTJS:
downloadFile: function (a,b,c) { var Feed_id =this.getMyFeedwindow().down('form').getComponent('FeedId').text; Ext.Ajax.request({ url: '/Feed/Download',method: 'GET',params: { fileID: Feed_id,//this.form.getComponent('file').value,},failure: function (response) { alert('Failed !'); },success: function (response) { alert('success!'); },}); },
然后用这个代码块满足请求.
C#:
public void Download(string fileID){ Response.ContentType = "application/force-download"; response.addheader("Content-disposition","attachment; Filename=\"logo1.jpg\""); Response.BinaryWrite(data); Response.End(); }
当我用firebug检查网络时,似乎我的请求使用这些参数成功返回.
Cache-Control private Content-disposition attachment; filename="logo1.jpg" Content-Type application/force-download Date Wed,09 Jan 2013 12:51:54 GMT Server Microsoft-IIS/8.0 transfer-encoding chunked X-AspNet-Version 4.0.30319 X-AspNetMvc-Version 4.0 X-Powered-By ASP.NET X-SourceFiles =?UTF-8?B?RTpcVXRrdUNhblxQcm9qZWN0c1xURlNcQlRPTVxCVE9NXEZlZWRcRG93bmxvYWQ=?=
虽然它返回成功,但下载无法启动.我阅读了很多问题和文章,但大多数答案都说添加force-download标题解决了这个问题.我想念哪一点?谢谢.
解决方法
> System.Web.MVC.FilePathResult
> System.Web.MVC.FileStreamResult
> System.Web.MVC.FileContentResult
大多数时候我使用的是System.Web.MVC.FileStreamResult.像它一样使用它
FileStreamResult result = new FileStreamResult(stream,contentType); result.FileDownloadName = filename; // name of the downloaded file
根据您的编辑更新一些信息
您无法使用XHR请求开始下载.但至少有两种方法可以做到:
>如果文件路径已修复,并且您知道它设置了top.location.href =“YourPath”;在ajax调用的成功处理程序中. [信息约top.location.href]>如果你动态创建文件并想要返回它,你应该创建一个隐藏的iframe并在其中注入一个表单然后执行请求.
ajax 请求 文件下载
针对 ajax 请求,返回二进制流的形式,实现文件下载
var options = {
"url": "/haha/attachment/download.do?eventid=" + file.oid + "&token=" + localStorage.getItem("token"),
"method": ''post''
}
var config = $.extend(true, {
method: ''get''
}, options);
var $iframe = $(''<iframe id="down-file-iframe" />'');
var $form = $(''<form target="down-file-iframe" method="'' + config.method + ''" />'');
$form.attr(''action'', config.url);
for (var key in config.data) {
$form.append(''<input type="hidden" name="'' + key + ''" value="'' + config.data[key] + ''" />'');
}
$iframe.append($form);
$(document.body).append($iframe);
$form[0].submit();
$iframe.remove();
Ajax文件下载
<html>
<head>
<Meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="jquery-1.4.2.js"></script>
</head>
<body>
<a href="a" rel="nofollow" target="_blank">http://sishuok.com/forum/download?filename=2012/8/3/59e99e4584d24c982bba2ecbb52459ee__hadoop%E5%88%9D%E7%BA%A7ppt.rar">a标签下载</a>
<input
type='button'
value="修改地址栏下载"
onclick="window.location.href='http://sishuok.com/forum/download?filename=2012/8/3/59e99e4584d24c982bba2ecbb52459ee__hadoop%E5%88%9D%E7%BA%A7ppt.rar'">
<input
type='button'
value="打开新窗口下载"
onclick="window.open('http://sishuok.com/forum/download?filename=2012/8/3/59e99e4584d24c982bba2ecbb52459ee__hadoop%E5%88%9D%E7%BA%A7ppt.rar')">
<iframe id="fileDownFrame" src=""https://www.jb51.cc/tag/dis/" target="_blank">display:none; visibility:hidden;"></iframe>
<input
type='button'
value="ajax下载"
onclick='$("#fileDownFrame").attr("src","http://sishuok.com/forum/download?filename=2012/8/3/59e99e4584d24c982bba2ecbb52459ee__hadoop%E5%88%9D%E7%BA%A7ppt.rar");'>
<!--
ajax下载或者使用 jquery.fileDownload 插件
http://johnculviner.com/post/2012/03/22/Ajax-like-feature-rich-file-downloads-with-jQuery-File-Download.aspx
服务器端设置不缓存
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
-->
</body>
</html>
通过js生成一个form,用这个form提交参数,并返回“流”类型的数据。在实现过程中,页面也没有进行刷新。
var form = $("<form>"); //定义一个form表单
form.attr('style','display:none'); //在form表单中添加查询参数
form.attr('target','');
form.attr('method','post');
form.attr('action',"exportSms");
var input1 = $('<input>');
input1.attr('type','hidden');
input1.attr('name','exportPostTime');
input1.attr('value',timeString);
$('body').append(form);//将表单放置在web中
form.append(input1); //将查询参数控件提交到表单上
form.submit(); //表单提交
Ajax文件下载使用Jquery,PHP
我有几个PHP脚本来处理$ _GET变量的处理工作,但是当使用Ajax进行访问时,它们停止工作。
Ajax / PHP代码im使用如下:
function ajaxDown(){ $('#downloadmsg').html( '<img src=\"media/images/ajaxloader.gif\" width=\"128\" height=\"15\">'); $('#downloadmsg').load( 'media/downloads/downManager.PHP?file=".$filequery['filename']."&ftype=".$downex[1]."'); }
请查看我的代码,并帮助我找到我做错了什么。
感谢名单
一种可能起作用的方法是在HTML中创建一个隐藏的iframe,如下所示:
<iframe id="secretIFrame" src=""https://www.jb51.cc/tag/dis/" target="_blank">display:none; visibility:hidden;"></iframe>
然后,将iframe的attr设置为querystring:
$("#secretIFrame").attr("src","myPHPscript.PHP?option1=apple&option2=orange");
然后使用PHP头来强制下载源码(这里是一个使用八位字节流的脚本中的一个导出器头文件的示例):
header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate,post-check=0,pre-check=0"); header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download"); header("Content-disposition: attachment;filename=data.xls "); header("Content-transfer-encoding: binary ");
希望这可以帮助!
Ajax文件下载问题
我正在应用程序中下载动态文件,并使用iframe来模拟ajax。我正在做的是,当下载请求发出后,我将创建一个动态的不可见iframe,并将iframe的src设置为下载网址。我能够成功下载该文件,但要求是显示一个下载下载指示器一旦开始下载,并在下载对话框出现后立即完成。我在创建iframe后提供了回调,以显示下载指示器已成功运行,并在iframe的“
onload”上提供了另一种方法,期望出现下载对话框时,将调用它。但不幸的是,这不起作用,因此即使下载完成后,我的进度指示器仍然存在。我无法删除它。然后我意识到,由于响应的内容类型不是html,它将由一个单独的进程提供服务,这将导致下载对话框,并且因为从未调用过我的onload方法。请让我知道一个解决方案。
答案1
小编典典发出下载请求时,您应该在客户端中启动计时器,该计时器以指定的时间间隔测试iframe的状态:
if ( ( iframe.document && iframe.document.readyState == ''complete'' ) || iframe.contentDocument ){ stopTimer(); closePopupDialog();}
今天的关于Extjs Ajax文件下载请求C#MVC和ajaxfileupload excel的分享已经结束,谢谢您的关注,如果想了解更多关于ajax 请求 文件下载、Ajax文件下载、Ajax文件下载使用Jquery,PHP、Ajax文件下载问题的相关知识,请在本站进行查询。
本文标签: