Skip to content

Instantly share code, notes, and snippets.

@neodigm
Created January 9, 2024 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neodigm/033bc49885bd01349b7b057c34b96817 to your computer and use it in GitHub Desktop.
Save neodigm/033bc49885bd01349b7b057c34b96817 to your computer and use it in GitHub Desktop.
const oResp = fetch("/uri/", {
"body": "IPOID=" + formData.IPOID + "&ProjectID=" + formData.ProjectID,
"headers": { "content-type": "application/x-www-form-urlencoded; charset=UTF-8" },
"method": "POST", "mode": "cors", "credentials": "include"
})
.then( ( resp )=>{
if( !resp.ok ) throw new Error( resp.status )
return resp.arrayBuffer();
} )
.then( ( buffer )=>{
const elLink = document.createElement("a")
const blobFile = new Blob([ buffer ], { type: 'application/pdf' })
const urlFile = URL.createObjectURL( blobFile )
elLink.setAttribute( "href", urlFile )
elLink.setAttribute( "download", sFileName )
elLink.style.visibility = "hidden"
document.body.appendChild( elLink )
elLink.click()
} )
.catch( ( error )=>{
console.log( "Request Failed: " + error )
} )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment