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

108
Vistas
JavaScript XMLHttpRequest return status 0

I'm pretty new to JavaScript / TypeScript and I was writing this tiny piece of TS code to retreive the HTML from another page on my server and put it on a <div id='container'> tag.

let container = document.getElementById("container") as HTMLDivElement;
let req = new XMLHttpRequest();

function getContent(page: string): string {
    let content = "";
    const basePath = "content/";
    const url = basePath + page;
    
    req.open("GET", url);
    req.send();
    content = req.responseText;
    container.innerHTML = content;
    console.log(req.status);
    return content;
}

getContent('home'); 

Now, when I open the page on the browser (I'm using GitHub Pages for hosting) all I get is a blank page and a req.status of 0 in the console. Of course the file content/home.html exists. I tried both getContent('home') and getContent(home.html) but neither worked.

What am I doing wrong?

Thank you to all.

about 4 years ago · Santiago Gelvez
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