OK, this one is obvious. The user submits the form by clicking on the corresponding submit button on the desired row of your table. Why care about javascript when you have standard HTML forms which can submit data to the server in a purely browser agnostic manner, like shown in point 1.? Yeah, that's like standard HTTP protocol. That's exactly what any browser's gonna do when it handles the previously shown HTTP response from a server.
And if you wanted a little bit of additional fanciness, just enhance the HTML form upon submission using javascript in order to append any required fields as hidden input elements that you would like to send to the server. And then leave it to the browser to handle the download. The browser will display the Save As dialog box according to its own download settings. Whether or not the file gets downloaded depends on whether the OS has a program to handle opening the file.
You can force the download override opening the file by making an anchor with the download attribute. Anyway I want to share the solution I come up with. I created two end poin in my Flask app:. 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 5 years, 10 months ago. Something like this:. Unless we have static files available publicly on the server, we need to create content using a Blob , a file-like object in JavaScript.
Of course, a Blob object has a lot more than just a plain text type. You can learn more in the official documentation.
We can dynamically create an anchor element in JavaScript using createElement and then programmatically invoke the click event. Here is a basic example:. But to download a file, we need to pass it download and href attributes. The download will hold the file name and extension and the href will require a URL. Learn Bootstrap quickly to become a master.
Code has been added to clipboard! Reading time 3 min. Contents 1. What are automatic downloads with JavaScript? Making JavaScript download files without the server 3. Using FileSaver. What is a Blob? JavaScript download: useful tips. Example Copy. Try it Live Learn on Udacity. Pros Simplistic design no unnecessary information High-quality courses even the free ones Variety of features. Nanodegree programs Suitable for enterprises Paid certificates of completion.
Pros Easy to navigate No technical issues Seems to care about its users. Huge variety of courses day refund policy Free certificates of completion. Pros Great user experience Offers quality content Very transparent with their pricing.
0コメント