I have a function which is called via a user action in my template:
<a href="{% url 'channels:download_channel' channel.id %}" onclick="showLoader()">
download_channel
is a function that merges audio files (into one file) and initiates a file for download. This can take some time and isn't instantaneous. So I show a spinner.
showLoader()
is a javascript function that simply shows a spinner to let the user know the process/download is ongoing.
My problem is when the download is finished on the server side, I have no way of communicating with the template to hide the spinner
I've tried via ajax, but I guess you can't initiate downloads that way (unsafe). This was the ideal solution I was hoping would work.
function downloadChannel() {
showLoader()
$.ajax({
type:'GET',
url:'{% url "channels:download_channel" topic.id %}',
success:function(json){
console.log('got some success of heah')
hideLoader();
location.reload();
},
error : function(xhr,errmsg,err) {
console.log(xhr.status + ": " + xhr.responseText);
hideLoader();
// provide a bit more info about the error to the console
}
});
}
I've looked at django channels, but sockets seem like a big setup for such a simple problem.
I'm a bit stumped on how to properly approach this problem.
Any feedback is greatly appreciated