My goal is to let a user download a PDF from my server. The most mon approach to this would be to simply have a link with a download attribute like so
<a href="" download>click here</a>
The problem with this is that I cannot monitor the download or have a callback when it is finished. The browser just hangs until the request is processed and suddenly pops up a download when it is done.
So now I am getting pdf data from a server with AJAX and want to download the data via the browser.
So I have something along the lines of
$.get("", (data) ->
#need to somehow trigger a download with this data
)
I've been searching for a while to no avail. Any help is appreciated. Thanks!
--edit To clarify why this is not a duplicate, I am asking about triggering a download on data, not a local file.
My goal is to let a user download a PDF from my server. The most mon approach to this would be to simply have a link with a download attribute like so
<a href="http://mysource.pdf" download>click here</a>
The problem with this is that I cannot monitor the download or have a callback when it is finished. The browser just hangs until the request is processed and suddenly pops up a download when it is done.
So now I am getting pdf data from a server with AJAX and want to download the data via the browser.
So I have something along the lines of
$.get("http://mysource.pdf", (data) ->
#need to somehow trigger a download with this data
)
I've been searching for a while to no avail. Any help is appreciated. Thanks!
--edit To clarify why this is not a duplicate, I am asking about triggering a download on data, not a local file.
Share Improve this question edited Jul 10, 2015 at 21:22 tbogatchev asked Jul 10, 2015 at 21:09 tbogatchevtbogatchev 1,6513 gold badges15 silver badges22 bronze badges 3- Possible duplicate – ODelibalta Commented Jul 10, 2015 at 21:12
- search "monitor download progress with javascript" Most solutions seem to require server-side intervention. – Kevin B Commented Jul 10, 2015 at 21:13
- I would like to point out that this is NOT a duplicate of the linked thread. That thread is asking about downloading a file. I am downloading data. – tbogatchev Commented Jul 10, 2015 at 21:17
1 Answer
Reset to default 4$('a').click(function(event) {
event.preventDefault();
$.get("http://mysource.pdf", (data) ->
window.location.href = $(this).attr('href');
)
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745430512a4627367.html
评论列表(0条)