Skip to content

Instantly share code, notes, and snippets.

@cihat
Created February 1, 2021 12:33
Show Gist options
  • Select an option

  • Save cihat/0b2b379a6c75f9f1920a068a01ac9c47 to your computer and use it in GitHub Desktop.

Select an option

Save cihat/0b2b379a6c75f9f1920a068a01ac9c47 to your computer and use it in GitHub Desktop.
Making AJAX calls in pure JavaScript
const getCountryData = country => {
const request = new XMLHttpRequest();
request.open('GET', `https://restcountries.eu/rest/v2/name/${country}`);
request.send();
request.addEventListener('load', function () {
const [data] = JSON.parse(this.responseText);
console.log(data);
countriesContainer.insertAdjacentHTML('beforeend', html);
countriesContainer.style.opacity = 1;
});
getCountryData('türkiye');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment