MCPcopy Create free account
hub / github.com/PhilopaterHany/JavaScript-Bootcamp / getData

Function getData

Lessons/Week 22/182 - Promise And XHR.js:5–19  ·  view source on GitHub ↗
(apiLink)

Source from the content-addressed store, hash-verified

3*/
4
5const getData = (apiLink) => {
6 return new Promise((resolve, reject) => {
7 let myRequest = new XMLHttpRequest();
8 myRequest.onload = function () {
9 if (this.readyState === 4 && this.status === 200) {
10 resolve(JSON.parse(this.responseText));
11 } else {
12 reject(Error("No Data Found"));
13 }
14 };
15
16 myRequest.open("GET", apiLink);
17 myRequest.send();
18 });
19};
20
21getData("https://api.github.com/users/elzerowebschool/repos")
22 .then((result) => {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected