Created
December 11, 2019 11:23
-
-
Save RobinHerbots/940b0fce3248b4deb1de7a6e4290635b to your computer and use it in GitHub Desktop.
Ajax file download
This file contains 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
$('#GetFile').on('click', function () { | |
$.ajax({ | |
url: 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/172905/test.pdf', | |
method: 'GET', | |
xhrFields: { | |
responseType: 'blob' | |
}, | |
success: function (data) { | |
var a = document.createElement('a'); | |
var url = window.URL.createObjectURL(data); | |
a.href = url; | |
a.download = 'myfile.pdf'; | |
document.body.append(a); | |
a.click(); | |
a.remove(); | |
window.URL.revokeObjectURL(url); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment