Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

232
Views
How do i download a file using AJAX in javascript?

I need to download a file from a different server (from Documentum) through a VBCS application. If i put the URL of the document into postman and provide basic authentication and then click on send and download, I am able to download the document but when i try to do it through AJAX and javascript, the document does not get downloaded but i can see the contents of the document in the response of my GET call. Following is the code that i have written -

     var xhrdoc = new XMLHttpRequest();
     xhrdoc.open("GET", docURL1);
 


     xhrdoc.setRequestHeader("Accept", "*/*");
    // xhrdoc.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
     xhrdoc.setRequestHeader("Content-Type","application/octet-stream");
     xhrdoc.setRequestHeader("Content-Disposition", "attachment");
     xhrdoc.setRequestHeader("Authorization","Basic "+btoa(username+":"+password));
     console.log("Log:docURL",xhrdoc.status);
    
 // window.location.href = docURL1;

     xhrdoc.send();

    

    xhrdoc.onload = function () {
  console.log("inside onload for get doc");
   console.log("Log: inside getdoc",xhrdoc.status, "Status");
  console.log("Log: inside getdoc",xhrdoc.responseURL,"ResponseURL");
  console.log("Log inside get doc response text",xhrdoc.responseText);
  console.log("log inside response ", xhrdoc.response);

Any help will be really appreciated. Thank you!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!