You need to create a URL from Blob data and add it to href and trigger a click.
const saveData = (() => {
const a = document.createElement('a');
a.style = 'display: none';
document.body.appendChild(a);
return (data, fileName, type = 'octet/stream') => {
const blob = new Blob([data], { type });
if (navigator.msSaveBlob) {
return navigator.msSaveBlob(blob, fileName);
}
const url = URL.createObjectURL(blob);
a.href = url;
a.download = fileName;
a.click();
URL.revokeObjectURL(url);
return true;
};
})();
So this function will take your data and complete these two steps, and you can use it something like this:
$.ajax({
method: "POST",
contentType: "application/x-www-form-urlencoded",
url: "<endpoint here>",
data: {
"tokenId": token,
"downloadId": "cz98567354",
"saveAs": "AllContents"
}
})
.done((data) => saveData(data, 'myDownload.zip'));
, , Blobs, window.open base64. , , , , ES5' , .