Ameba Ownd

アプリで簡単、無料ホームページ作成

Bethanie Todd's Ownd

Jquery post file download

2021.12.20 00:49






















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. 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. I know this kind of old, but I think I have come up with a more elegant solution.


I had the exact same problem. The issue I was having with the solutions suggested were that they all required the file being saved on the server, but I did not want to save the files on the server, because it introduced other problems security: the file could then be accessed by non-authenticated users, cleanup: how and when do you get rid of the files. And like you, my data was complex, nested JSON objects that would be hard to put into a form.


What I did was create two server functions. The first validated the data. If there was an error, it would be returned. Then, on the client, I have a form that has only one hidden input and posts to a second server function. I set the hidden input to the base64 string and submit the format. The form could submit to a new window or an iframe on the page and the file will open up.


In short, there is no simpler way. You need to make another server request to show PDF file. It is been a while since this question was asked but I had the same challenge and want to share my solution. Instead of saving the file between the requests, it saves the post data. It seems to be both simple and effective. I think the best approach is to use a combination, Your second approach seems to be an elegant solution where browsers are involved.


Can someone help point me in the right direction? Replies 3. Re: Download file from JQuery Post 9 years ago. Ajax ignores all those pretty headers!


Leave a comment on jakecigar's reply. Aw bummer, that's too bad. Guess I'll have to figure out another method. Leave a comment on dmikester1's reply. Making a hidden form with the hidden values needed, and a. Change topic type Cancel. Link this topic. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 11 years, 3 months ago. Active 4 months ago. Viewed k times. There must be a simpler way to accomplish this. Any other ways to accomplish this? Improve this question.


Tauren Tauren Put the header in php file. No need to send any ajax or get requests — abhishek bagul. Add a comment. Active Oldest Votes. Improve this answer. SamStephens SamStephens 5, 6 6 gold badges 33 33 silver badges 44 44 bronze badges. Then it also warns me the file may be dangerous. If I visit the retData. Looking around the internet, it looks like you can have issues with PDFs in iFrames if your server is not setting Content-Type and Content-Disposition properly. I haven't actually used this solution myself, just clarified a previous solution, so don't have any other advice I'm afraid.


Tauren: If you agree that this is a better answer, note that you can switch the accepted answer at any time - or even remove the accept mark entirely. Simply check off the new answer and the accept mark will be transferred. Old question, but it was brought up in flags recently. Show 4 more comments.


Jason Williams 2, 25 25 silver badges 34 34 bronze badges. JoshBerke JoshBerke No support for download attribute on IE and Safari : caniuse. You can open a new window and put content there, but not sure about a PDF or Excel You should free up browser memory after calling click : window.


JoshBerke This is old but it works on my end. How can I get it to open up my directory immediately to save rather than saving to my browser? Also is there a way to determine the name of the incoming file? It will corrupt binary files, because they get converted to strings using encoding, and result is not very close to original binary May use mimetypes to not corrupt the information as used here with PDFs: alexhadik. Data; formGenerate.


Al though, there are few alternatives but they are not perfect and won't work on all browsers: Look at data URI scheme. If binary data is small then you can perhaps use javascript to open window passing data in URI.


VinayC VinayC It looks like that may be the only way to do it in a single request.