Created
June 3, 2018 15:46
-
-
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…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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