Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

233
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda