|
@@ -45,25 +45,25 @@ function linkChecker(str, container) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-//
|
|
|
-// function myFetch(url){
|
|
|
-// return new Promise(function (resolve, reject){
|
|
|
-// const xhr = new XMLHttpRequest()
|
|
|
-// xhr.open('get', url)
|
|
|
-// xhr.onload = function () {
|
|
|
-// if (xhr.status >= 200 && xhr.status < 300) {
|
|
|
-// resolve(xhr.response);
|
|
|
-// } else {
|
|
|
-// reject(() => alert('something went wrong'));
|
|
|
-// }
|
|
|
-// xhr.send();
|
|
|
-// }});
|
|
|
-// }
|
|
|
-// myFetch('https://swapi.dev/api/peope/4/')
|
|
|
-// .then(res => console.log(res))
|
|
|
-//
|
|
|
-// function delay(ms) {
|
|
|
-// return setTimeout(() => console.log('delay worked'), ms)
|
|
|
-// }
|
|
|
-// Promise.race([myFetch('https://swapi.dev/api/peope/4/'), delay(300)]).then(val => console.log(val))
|
|
|
-// Promise.race([myFetch('https://swapi.dev/api/peope/1/'), delay(200)]).then(val => console.log(val))
|
|
|
+
|
|
|
+function myFetch(url){
|
|
|
+ return new Promise(function (resolve, reject){
|
|
|
+ const xhr = new XMLHttpRequest()
|
|
|
+ xhr.open('get', url)
|
|
|
+ xhr.onload = function () {
|
|
|
+ if (xhr.status >= 200 && xhr.status < 300) {
|
|
|
+ resolve(xhr.response);
|
|
|
+ } else {
|
|
|
+ reject(() => alert('something went wrong'));
|
|
|
+ }
|
|
|
+ xhr.send();
|
|
|
+ }});
|
|
|
+}
|
|
|
+myFetch('https://swapi.dev/api/peope/4/')
|
|
|
+ .then(res => console.log(res))
|
|
|
+
|
|
|
+function delay(ms) {
|
|
|
+ return setTimeout(() => console.log('delay worked'), ms)
|
|
|
+}
|
|
|
+Promise.race([myFetch('https://swapi.dev/api/peope/4/'), delay(300)]).then(val => console.log(val))
|
|
|
+Promise.race([myFetch('https://swapi.dev/api/peope/1/'), delay(200)]).then(val => console.log(val))
|