AJAX调用返回数据,但不提示下载 [英] AJAX call returns data but does not prompt a download
问题描述
我有一个ajax调用,该调用成功地调用了一个本身正常工作的页面.单击按钮,然后下载PDF.但是,当我使用相同的请求类型和URL进行AJAX调用时,会返回data
,但不会提示下载.
I have an ajax call that successfully calls a page that by itself works fine. You click the button, and a PDF downloads. However, when I make an AJAX call using the same request type and url, the data
is returned, but does not prompt a download.
我的电话:
$("#download-pdf").live('click', function(){
$.ajax({
url: $(this).parents('form').attr('action'),
type: 'POST',
success: function(data){
console.log(data);
}
});
return false;
});
数据将作为未解析的PDF返回.所以我知道那里的信息.它只是不会导致下载.有什么花招吗?
Data is returned as what would be an unparsed PDF. So I know the information is there. It just doesn't cause a download. Any tricks?
推荐答案
强制下载的唯一方法是使用标准"表单提交方法刷新页面.使用Ajax,您将收到原始输出数据(PDF),并且不会弹出任何保存对话框
The only way to force a download is to refresh the page using the "standard" form submission method. With Ajax you'll receive the raw output data (PDF) and no save dialog will ever pop up
这篇关于AJAX调用返回数据,但不提示下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!