Skip to content

Instantly share code, notes, and snippets.

@Theo-denBlanken
Created September 25, 2020 08:50
Show Gist options
  • Save Theo-denBlanken/5341b5da0c2d193bfc232bc563a2ae35 to your computer and use it in GitHub Desktop.
Save Theo-denBlanken/5341b5da0c2d193bfc232bc563a2ae35 to your computer and use it in GitHub Desktop.
HTTPRequest in JavaScript asynchroon JS
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
if(xhr.readyState == 4 && xhr.status ==200) {
let resultaat = JSON.parse(xhr.responseText);
console.log(resultaat);
}
}
xhr.open('GET', 'boeken.json', true);
xhr.send();
console.log('Het script heeft deze regel uitgevoerd. Dit zal eerder gebeuren dan regel 6!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment