Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

102
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda