Download file using ajax call

Download file using ajax call

download file using ajax call

stackoverflow.com › questions › download-file-using-an-ajax-request. download file using an ajax request, Downloading files from POST requests is actually a bit more We're going to implement a really simple server which is. show a normal link for the user to download a file. However it is also possible to download a file using a Javascript AJAX request.

Download file using ajax call - boring

Asked
I have a Struts2 action in the server side for file downloading.
2019 modern browsers updateThis is the approach I'd now recommend with a few caveats:
  • A relatively modern browser is required
  • If the file is expected to be very large you should likely do something similar to the original approach (iframe and cookie) because some of the below operations could likely consume system memory at least as large as the file being downloaded and/or other interesting CPU side effects.
2012 Original jQuery/iframe/Cookie based approachBluish is completely right about this, you can't do it through Ajax because JavaScript cannot save files directly to a user's computer (out of security concerns). Unfortunately pointing the main window's URL at your file download means you have little control over what the user experience is when a file download occurs.I created jQuery File Download which allows for an "Ajax like" experience with file downloads complete with OnSuccess and OnFailure callbacks to provide for a better user experience. Take a look at my blog post on the common problem that the plugin solves and some ways to use it and also a demo of jQuery File Download in action. Here is the sourceHere is a simple use case demo using the plugin source with promises. The demo page includes many other, 'better UX' examples as well.
You can with HTML5NB: The file data returned MUST be base64 encoded because you cannot JSON encode binary dataIn my response I have a data structure that looks like this:
The simple way to make the browser downloads a file is to make the request like that:
Источник: [https://torrent-igruha.org/3551-portal.html]

Download file using ajax call

2 thoughts to “Download file using ajax call”

Leave a Reply

Your email address will not be published. Required fields are marked *