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

103
Views
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
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!