PDF is not character data. It's binary data. You want to use completely new request for this. To assist you more with the server side code, you'll need to tell more about the language used and post an excerpt of the code attempts.
I don't really think that any of the past answers spotted out the problem of the original poster. In its "heart" it creates a "temporary" HTML form containing the given data as input fields. This form is appended to the document and posted to the desired URL. Right after that the form is removed again:. Update Mayur's answer looks pretty promising and very simple in comparison to the jQuery plug-in I referred to.
This is how i solve this issue. The answer of Jonathan Amend on this post helped me a lot. The example below is simplified. A simple event on button click. It creates an AjaxDownloadFile object. The AjaxDownloadFile class source is below. What worked for me is the following code, as the server function is retrieving File memoryStream. This worked for me. Found this plugin here. Concerning the answer given by Mayur Padshala this is the correct logic to download a pdf file via ajax but as others report in the comments this solution is indeed downloads a blank pdf.
The reason for this is explained in the accepted answer of this question : jQuery has some issues loading binary data using AJAX requests, as it does not yet implement some HTML5 XHR v2 capabilities, see this enhancement request and this discussion.
To fix the blank PDF issue in post request to get stream data like PDF, we need to add response type as 'arraybuffer' or 'blob' in request. Hope this will save you a few hours and spare you from a headache. Solution was this:. Include download. This snippet is for angular js users which will face the same problem, Note that the response file is downloaded using a programmed click event. If you have to work with file-stream so no physically saved PDF like we do and you want to download the PDF without page-reload, the following function works for us:.
Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 11 years, 10 months ago. Active 1 year, 7 months ago. Viewed k times. I have an action class that generates a PDF. The contentType is set appropriately. Mike Nayn Nayn 3, 8 8 gold badges 36 36 silver badges 47 47 bronze badges. Add a comment. Active Oldest Votes. Community Bot 1 1 1 silver badge. Mayur Padshala Mayur Padshala 1, 2 2 gold badges 18 18 silver badges 19 19 bronze badges.
Does it work on chrome? Security code:. Required Invalid security code. I declare, I accept the site's Privacy Policy. Add Comment. Disclaimer : The code samples and API available at www. You are free to use it for commercial as well as non-commercial use at your own risk, but you cannot use it for posting on blogs or other tutorial websites similar to www. All the code samples and API provided by the authors are solely their creation and neither the author nor the site are responsible if it does not work as intended.
I agree to the above terms. Download Required. What our readers say. Error Details. PDF is not character data. You want to use completely new request for this. This form is appended to the document and posted to the desired URL. Right after that the form is removed again:. This is how i solve this issue.
The answer of Jonathan Amend on this post helped me a lot. The example below is simplified. A simple event on button click. It creates an AjaxDownloadFile object. The AjaxDownloadFile class source is below. This worked for me.
0コメント