In a view HTML
I have a href which has a data_id with an 'X' value and a class, when I click on the link I do ajax validating if that data (data_id) really exists, what I try to do is that in the done if I downloaded the file but ps do not do anything but I can not find the way to download it, it does not help to use <a href="download/mi_archivo.jpg" download="mi_archivo.jpg">
within HTML
since I'm looking for a more elegant way to do it with JS.
This is the code with which I try to make it.
$(document).on("click", ".it-file", function()
{
var txitxa = $(this).data("fileinformationstdid");
$.ajax({
url: 'downloadfileinformationstdid',
type: 'POST',
data: {'txitxa' : txitxa}
})
.done(function(response) {
var answer = $.parseJSON(response);
if(answer <= 0)
{
alert("Error","Este archivo no se encuentra en la base de
datos","error");
}
else
{
var url="../../download/" + answer[0].formato_filenamestd;
window.open(url, 'Download');
}
})
.fail(function() {
console.log("error");
});