AJAX调用返回数据,但不提示下载

编程入门 行业动态 更新时间:2024-10-27 20:35:17
本文介绍了AJAX调用返回数据,但不提示下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个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调用返回数据,但不提示下载

本文发布于:2023-10-26 21:41:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1531427.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:但不   提示   数据   AJAX

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!