Skip to content

Instantly share code, notes, and snippets.

@Ormadont
Created June 3, 2018 15:46
Show Gist options
  • Save Ormadont/9fa4dc71f88de45026ed84efd9329c75 to your computer and use it in GitHub Desktop.
Save Ormadont/9fa4dc71f88de45026ed84efd9329c75 to your computer and use it in GitHub Desktop.
//boilerplate code for an AJAX GET request using an XMLHttpRequest object const xhr = new XMLHttpRequest(); const url = 'https://api-to-call.com/endpoint'; //xhr - XMLHttpRequest, it is a common practice to name this object xhr.responseType = 'json'; xhr.onreadystatechange = () => { //The purpose of this conditional statement checks to see if th…
//boilerplate code for an AJAX GET request using an XMLHttpRequest object
const xhr = new XMLHttpRequest();
const url = 'https://api-to-call.com/endpoint';
//xhr - XMLHttpRequest, it is a common practice to name this object
xhr.responseType = 'json';
xhr.onreadystatechange = () => {
//The purpose of this conditional statement checks to see if the request has finished.
if (xhr.readyState === XMLHttpRequest.DONE) {
return xhr.response;
}
}
//.open() creates a new request and the arguments passed in determine the type and URL of the request.
xhr.open('GET', url);
xhr.send();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment