Trying to implement an ajax request for downloading a file. Here's the code snippet:
const downloadFile = (element) => {
$.ajax({
url: element.id,
type: 'GET',
success: (result) => {
window.location=element.id;
},
error: (request,msg,error) => {
alert(request.responseText);
}
})
}
And the corresponding HTML element:
'<td>' + `<a id=hiddenAPIRoute href="#" onclick="downloadFile(this)">Download</a>` + '</td>' +
Able to achieve download functionality, but facing double download issue. Prefer using ajax for improved error handling. While aware of html 5's download attribute, want to incorporate an alert in case the file is inaccessible.