Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //boilerplate code for an AJAX GET request using an XMLHttpRequest object.
- const xhr = new XMLHttpRequest(); //common practice to name this object xhr
- const url = 'https://api-to-call.com/endpoint';
- xhr.responseType = 'json'; //the response is going to be formatted into JSON type
- xhr.onreadystatechange = () => { //make the event handler equal to an anonymous arrow function
- if (xhr.readyState === XMLHttpRequest.DONE) { //Purpose of this conditional statement checks to see if the request has finished
- return xhr.response;
- }
- }
- xhr.open('GET', url); //.open() creates a new request and the arguments passed in determine the type and URL of the request.
- xhr.send(); //send the request to the server.
Add Comment
Please, Sign In to add comment