Skip to content

Instantly share code, notes, and snippets.

@edgardo001
Forked from AxelUser/download_ajax.js
Created June 1, 2022 13:04
Show Gist options
  • Save edgardo001/c0ca5263dbc3fca7cb2dda574ac007b4 to your computer and use it in GitHub Desktop.
Save edgardo001/c0ca5263dbc3fca7cb2dda574ac007b4 to your computer and use it in GitHub Desktop.
How to download file in base64 format by ajax request to your api
$.ajax({
url: "http://api.yoursite.com",
data: data,
type: "POST"
}).done(function(result) {
var link = document.createElement("a");
document.body.appendChild(link);
link.setAttribute("type", "hidden");
link.href = "data:text/plain;base64," + result;
link.download = "data.zip";
link.click();
document.body.removeChild(link);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment