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

330
Views
When I try run a ajax call I get a error that says is undefined

I am trying to create ajax calls using information from countries but when I run the program it sends me the next error:"Uncaught TypeError: Cannot read properties of undefined (reading 'name') at XMLHttpRequest. (script.js:25)"

My Javascript code is the next one:

const request = new XMLHttpRequest();

request.open('GET', 'https://restcountries.com/v3.1/name/taiwan')
request.send();

request.addEventListener('load', function(){
  // console.log(this.responseText)
  const [data] = JSON.parse(this.responseText)
  console.log(data);

  const html= `<article class="country">
    <img class="country__img" src="${data.flags.svg}" />
    <div class="country__data">
      <h3 class="country__name">${data.name.common}</h3>
      <h4 class="country__region">${data.region}</h4>
      <p class="country__row"><span>๐Ÿ‘ซ</span>${(+data.population/1000000).toFixed(1)}</p>
      <p class="country__row"><span>๐Ÿ—ฃ๏ธ</span>${data.languages[0]}</p>
      <p class="country__row"><span>๐Ÿ’ฐ</span>${data.currencies[0].name}</p>
    </div>
  </article>`;

  countriesContainer.insertAdjacentHTML('beforeend', html)
  countriesContainer.style.opacity = 1;
});
about 4 years ago ยท Juan Pablo Isaza
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!