使用客户端事件调用(使用jquery ajax调用)在ASP.NET中创建可下载的PDF [英] Creating Downloadable PDF in ASP.NET With Client Side Event Call(using jquery ajax call)

查看:136
本文介绍了使用客户端事件调用(使用jquery ajax调用)在ASP.NET中创建可下载的PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在代码背后通过客户端调用(jquery ajax)创建pdf文档,但是
无法下载.我在视图状态下存储数据表数据并在那里恢复表格
客户端呼叫何时触发?
有没有办法下载它

i am able to create pdf document with client side call(jquery ajax) in codebehind but
unable to download. i am stroing data table data in view state and reteriving form there
when client side call fires?
is there way to download it

推荐答案

您无法做到这一点,因为您正在向服务器进行ajax调用,并且要从服务器下载某些内容,您必须进行完整的回发.
所以你可以这样.

在您的ajax调用中,将pdf文件制作或保存在服务器上,例如YourApplicationName/PDF/sample.pdf.
并从ajax调用返回此路径.现在您的文件已在服务器上,并且您知道该路径,但是剩下的东西就是下载此文件.为此,您可以使用complete函数和隐藏的iframe complete:function(){
//您的代码
you can''t do that as you are making ajax call to server and for downloading something from server you have to make complete postback.
So you can do like this.

in your ajax call make or save your pdf file on the server like YourApplicationName/PDF/sample.pdf.
and return this path from your ajax call.Now your file is on the server and you know the path but the thing that is remaining is download this file.For this you can use complete function and hidden iframe complete:function(){
//your code
var iframe = document.createElement("iframe");
               iframe.src = "GenerateFile.aspx?page=ViewDrawing";
               iframe.style.display = "none";
               document.body.appendChild(iframe);



}
并且在GenerateFile.aspx页面加载事件中,您可以编写pdf可下载的代码.



}
And in GenerateFile.aspx page load event you can write your pdf downloadable code.


我同意解决方案1.但是必须补充一点,您需要在您的文件中设置以下标头GenerateFile.aspx.否则,某些浏览器只会在隐藏的iframe中显示pdf.

context.Response.AddHeader("Content-Disposition","attachment; filename = my.pdf");
I agree on Solution 1. But have to add that you''ll need to set the following header in you GenerateFile.aspx. Otherwise some browsers will just diplay the pdf in the hidden iframe.

context.Response.AddHeader("Content-Disposition", "attachment;filename=my.pdf");


这篇关于使用客户端事件调用(使用jquery ajax调用)在ASP.NET中创建可下载的PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆