Skip to content

Instantly share code, notes, and snippets.

@brettvaida
Created November 25, 2017 17:51
Show Gist options
  • Save brettvaida/46b1ff3a08f068306f4854ca55b695f0 to your computer and use it in GitHub Desktop.
Save brettvaida/46b1ff3a08f068306f4854ca55b695f0 to your computer and use it in GitHub Desktop.
AJAX GET request boilerplate
const xhr = new XMLHttpRequest();
const url = 'https://api-to-call.com/endpoint';
xhr.responseType = 'json';
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
console.log(xhr.response);
}
};
xhr.open('GET', url);
xhr.send();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment