Created
March 13, 2022 10:49
-
-
Save mystikraz/6317b6d3c23f6986bcf233fd500ef05b to your computer and use it in GitHub Desktop.
download files, csv, pdf, excel, zip files using ajax javascript, jquery
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
| async function getZipAsync(form) { | |
| let response = await fetch("/BuyerReport/NewCharges" + '?' + (new URLSearchParams($(form).serialize())).toString()); | |
| let res = await response.blob(); | |
| if (res.type === 'application/zip') { | |
| const downloadUrl = window.URL.createObjectURL(res); | |
| const link = document.createElement('a'); | |
| link.setAttribute('href', downloadUrl); | |
| link.setAttribute('download', 'new charges report'); | |
| link.style.display = 'none'; | |
| document.body.appendChild(link); | |
| link.click(); | |
| window.URL.revokeObjectURL(link.href); | |
| document.body.removeChild(link); | |
| } else { | |
| alert("Your bulk export is larger than 50 MB. It will be sent as a link to your email address."); | |
| } | |
| showHideSpinner(false); | |
| } | |
| function download(data, filename, type) { | |
| var file = new Blob([data], { type: type }); | |
| if (window.navigator.msSaveOrOpenBlob) // IE10+ | |
| window.navigator.msSaveOrOpenBlob(file, filename); | |
| else { // Others | |
| var a = document.createElement("a"), | |
| url = URL.createObjectURL(file); | |
| a.href = url; | |
| a.download = filename; | |
| document.body.appendChild(a); | |
| a.click(); | |
| setTimeout(function () { | |
| document.body.removeChild(a); | |
| window.URL.revokeObjectURL(url); | |
| }, 0); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment