S
S
storm572018-07-13 12:21:44
JavaScript
storm57, 2018-07-13 12:21:44

Why is pdf not downloading correctly in firefox?

Through ajax, a pdf is downloaded using the following code

jQuery('#lp-download-pdf')
    .attr('href', string.trim())
    .attr('download', string.split('/').pop())[0]
     .click();

in chrome everything happens correctly, but in firefox if you upload 2 different files with the same name but different content, then the first uploaded file is downloaded all the time until the browser is restarted. the back end returns different files. What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alexalexes, 2018-07-13
@storm57

The above code is not directly related to the ajax technology. It just substitutes the href properties (by the presence of this property, you can guess that this is a link element) and download properties into the element with the lp-download-pdf id, then, forcibly, programmatically fires a click event, as if the user clicked on the element.
How the browser will react to a double "robotic" click on a link with the same href can only be guessed at. You can try to make the link unique on each click.
Substitute some random parameter to the link at this stage:

.attr('href', string.trim() + "?random_param=" + Math.round(Math.random() * 1000))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question