In my Django project, I have a pdf download button that generates a report. When I push the button I would like a modal showing that the report is being processed. When the pdf is downloaded, I would like the modal to hide automatically.
However, I am having some trouble with the last part. I know that Django sends a "GET" message in the backend, when the report is downloaded ("GET /download/140/...")
How can I "catch" the ("GET /download/140/...") event in my template?
Code:
<a href="{% url 'report-download' object.id %}" class="btn btn-grey" id="pdf-button"></a>
Show "processing" modal when download is initiated...
<script type="text/javascript">
$("#pdf-button").on("click", function(){
$('#myPDFModal').modal('show');
});
</script>
Attempt: Close "processing" modal when download is finished using Ajax...
<script type="text/javascript">
$(document).on('click', '#pdf-button', function(event)
{
event.preventDefault();
$.ajax({
url: '{% url 'report-download' object.id %}',
type: 'GET',
}).done(function(result) {
$('#myPDFModal').modal('hide');
});
});
</script>
The above code seems to work at showing/hiding the modal at the right "GET" event, but the pdf is not downloaded..