1
I’m hoping that by clicking the download button, js will access the endpoint that has the correct file path and start the download. What I did until it works, but it turns out he’s always "late".
example:
on the first click, it does not download anything
in the second click, download the first file
third click download the second file
I can’t leave the first fixed it because the file is generated at click time, with a random name.
How do I make it work right?
follow my js and html code
$("#download").click(function(e) {
e.preventDefault(); //stop the browser from following
$.getJSON("/get-path", function (path) {
$("#download").attr("href", path);
});
});
<a href="#" download style="text-decoration:none;" id="download_csv">
<label id="download_button" class="btn btn-info"><i class="fas fa-file-download"></i> <strong>Download</strong></label>
</a>