Jquery download file from url ajax
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. Improve this question. 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. Improve this answer. 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.
It does not work if you have a lot of parameters, because you will get too long url error. That sends the data in a very strange way to the server though. I wonder if it could be altered to create compliant POST? I faced the same issue and successfully solved it.
My use-case is this. After fetching content as a blob binary , we are creating a downloadable URL and attaching it to invisible "a" link then clicking it. I did a POST request here. Instead, you can go for a simple GET too.
Naren Yellavula Naren Yellavula 6, 2 2 gold badges 27 27 silver badges 22 22 bronze badges. Otherwise great solution for modern web browsers. Shayne Shayne 1, 1 1 gold badge 15 15 silver badges 17 17 bronze badges. This is working example. Is it possible to do that without iframe but without window. I suppose you could just append the hidden form to the bottom of the DOM.
Also possibly worth exploring is use of the Shadow dom , although thats not necessarily well supported on older browsers. In this code I am getting this error. The frame requesting access has a protocol of "http", the frame being accessed has a protocol of "data". Protocols must match.
How can I map this form to some model class? Thats probably a whole stack overflow question in and of it self. But the principle would be to take the name and path and store that, whilst pushing the file itself into a web accessible area of the file system, or something like amazon S3 for high availability — Shayne. Here is a quick fiddle jsfiddle. You are totally right load event is fired right after the server is done processing starts sending the file.
This is what i was looking for, 1- block the button and show processing so that the user can have a feedback that things are happening. Sorry my English. No need to create temporary files on the server.
On jQuery v2. Your exemple is just downloading a png file. But I need to download doc, pdf, zip, etc.. It should download the file in the download folder. Leave a comment on n00n46's reply. Can you share a link that does work? I used the plugin and only had to write a few lines of code. Change topic type Cancel. Link this topic. Provide the permalink of a topic that is related to this topic.
Save Close. Reply to n00n46's question. Top Reply. Statistics 4 Replies Views 1 Followers. Tags Cancel. Actions Permalink. All Forums Recent Posts. Create an anchor tag link on the normal HTML page.
We want to download a file when we click on an anchor tag link Download this file. Implementation and Folder structure is as shown below. Skip to content. Change Language. Related Articles. Table of Contents. Save Article. Improve Article. Like Article. Download File Using.
0コメント