See here for a similar post on using jQuery to clear forms: Resetting a multi-stage form with jQuery. You may also be running into an issue where the values are being repopulated by the struts value stack. In other words, you submit your form, do whatever in the action class, but do not clear the related field values in the action class. In this scenario the form would appear to maintain the values you previously submitted.
If you are persisting these in some way, just null each field value in your action class after persisting and prior to returning SUCCESS. 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 12 years, 3 months ago. Active 5 months ago. Viewed k times. How can I prompt a download for a user when they click a link.
Can this be done with jQuery, if so, how? Or should this be done with PHP or something instead? Improve this question. RedBlueThing Dodinas Dodinas 6, 22 22 gold badges 73 73 silver badges bronze badges. Additionally it's appended to the body which is a fix for Firefox and is removed from the body afterwards we don't want to have tons of invisible a tags on our body.
Keep in mind that this implementation uses plain JavaScript to make it easier for everybody to follow the example , but the actual download works the same for most frameworks jQuery, Vue, Angular, And, of course, you can find the entire implementation for this on GitHub. Well, as easy as vertically centering content in divs! The more I think about it, the more I like the last option. This way I can get information back about the request time to generate, size of file, error messages, etc.
The downside is extra file management on the server. This will wipe out any event bindings your page has, amongst other things. Create an element and use appendChild instead. Adding an iframe to the page that references that URL will result in the browser promoting the user to download the file, assuming that the web server has the appropriate mime type configuration. It will only download the file in Chrome, Firefox and Opera. This uses a download attribute on the anchor tag to force the browser to download it.
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.
Thanks man, I was looking for days This is phenomenal. Thanks for sharing. Thanks for sharing, it is working. Very helpfull. Just amazing, thank you very much! Server returned error Just found today a very simple solution window. Thanks, man, you saved the day! Sign up for free to join this conversation on GitHub.
Already have an account? Sign in to comment. You signed in with another tab or window. Reload to refresh your session.
0コメント