So i have a table listing files, each file's URL is stored as a data attribute on a button. On clicking a button I want to fire a Javascript/Ajax call that will download the file at the URL.
Now some caveats,
- The file needs to be downloaded via a download dialog or needs to just be added to the Browsers downloads as you would expect.
- The request needs to be able to take headers as this is a cross domain request.
- This needs to work on the main browsers (IE, Chrome, Firefox, Safari)
So far I have tried to use XMLHttpRequest:
e.preventDefault();
var csrftoken = getCookie('csrftoken');
var req = new XMLHttpRequest;
req.open("POST",$(this).data("url"));
req.setRequestHeader("MY HEADER", "HEADER VALUE;");
req.withCredentials = true;
req.send();
I've also tried Ajax GET request (which doesnt force the download) and using the Download attribute on an anchor tag (which doesnt accept headers).
Thanks