You can add your comment about this article using the form below. Make sure you provide a valid email address else you won't be notified when the author replies to your comment Please note that all comments are moderated and will be deleted if they are Not relavant to the article Spam Advertising campaigns or links to other sites Abusive content.
Please do not post code, scripts or snippets. Required Invalid Email Address. 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. After that I append the link to the document than simply clicking the link and removing the link afterwards. You don't need an iframe anymore. The interesting point is that this solution is only working with a " blob ".
As you can see in other answers, some are simply using a blob but not explaining why and how to create it. As you can read e. The problem is that your http-response might not be any of those. Therefore the first thing you must do is to convert your response to a blob.
This is what the first line does. Then you can use the " createObjectURL " with your newly created blob. If you than click the link your browser will open a file-save dialog and you can save your data. Obviously it s possible that you cannot define a fixed filename for your file to download. Then you must make your response more complex like in the answer from Luke.
And don't forget to free up the memory especially when you are working with large files. For more examples and information you can look at the details of the JS blob object. I found a fix that while it's not actually using ajax it does allow you to use a javascript call to request the download and then get a callback when the download actually starts.
I found this helpful if the link runs a server side script that takes a little bit to compose the file before sending it. I think there's a way to read get data using js so then no php would be needed. If the server is writing the file back in the response including cookies if you use them to determine whether the file download started , Simply create a form with the values and submit it:.
You need to reset the response or it will not download. This is helpful in case when you want to decide whether or not file needs to be downloaded after making form.
But I am referring to a page that must first be processed and then downloaded. I struggled with this issue for a long time. Finally an elegant external library suggested here helped me out. 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. Download a file by jQuery. Ajax Ask Question. Asked 10 years, 11 months ago.
Active 1 month ago. Viewed k times. I have a Struts2 action in the server side for file downloading. I marked it as a duplicate despite the platform difference, because as far as I can see the solution is the same You can't and don't need to do this through Ajax. Add a comment.
Active Oldest Votes. John Culviner John Culviner I love what you built but I suspect that to get more StackOverFlow credit your answer here should contain a bit more detail.
Specifically on how you solved the problem. I agree, a blog is a far better place to place a lengthy description of how to use your plugin and how it works. For example, this solves the problem by having the server set a cookie and having your javascript continuously look for the cookie until it exists.
Once it exists, we can assume that the download is complete. Royi, as I understand it AJAX can never support file downloads that result in a file download popup to save to disk. Have you found a way that I'm unaware of? Show 14 more comments. You don't need to do this through Ajax. Just use window.
Nice one Note that this requires the server to be setting a Content-Disposition header value of 'attachment', otherwise the browser will redirect to and display the response content — brichins. Or alternatively use window. To solve that use the iFrame solution — kofifus. The real problem with this solution - question is about POST request. Show 4 more comments. Community Bot 1 1 1 silver badge.
Luke Madhanga Luke Madhanga 4, 1 1 gold badge 38 38 silver badges 42 42 bronze badges. The a. Any idea? It simply doesn't, while all instinct says it must. I am using Chrome Version Thank you, I used this solution. Worked like a charm. Also, if you don't get a blob from the response, just create a new Blob. For example, when downloading a ZIP: response.
Andrea Ligios Andrea Ligios Sir, Your input: "Content-Disposition", "inline; This is the only answer that mentions "window.
Show 2 more comments. URL window. BSMP 4, 8 8 gold badges 33 33 silver badges 43 43 bronze badges. Thank you : — Kamlesh. Add a comment. Luca Ziegler Luca Ziegler 2, 16 16 silver badges 34 34 bronze badges. Alain Cruz Alain Cruz 3, 3 3 gold badges 19 19 silver badges 37 37 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown.
The Overflow Blog. Podcast Who is building clouds for the independent developer? Exploding turkeys and how not to thaw your frozen bird: Top turkey questions Featured on Meta.
Now live: A fully responsive profile. Reducing the weight of our footer. Linked 0. See more linked questions. Related Hot Network Questions.
0コメント