Last active
October 6, 2024 06:29
-
-
Save AxelUser/e080e793143f10dcc52c0e543282d5fe to your computer and use it in GitHub Desktop.
How to download file in base64 format by ajax request to your api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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
Thanks!