• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Pruebas Online
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

159
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!

almost 3 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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda