Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions promiseTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,42 @@ let addReq=(url)=> {
xhr.open('GET', url, true);
xhr.onload = function () {
let json = JSON.parse(this.responseText);
// if(json.getUsersData){
resolve(json);
}
xhr.send();
});
}

// }
Promise.all([addReq('http://www.json-generator.com/api/json/get/cevhxOsZnS'),
addReq('http://www.json-generator.com/api/json/get/cguaPsRxAi'),
addReq('http://www.json-generator.com/api/json/get/cfDZdmxnDm'),
addReq('http://www.json-generator.com/api/json/get/cfkrfOjrfS'),
addReq('http://www.json-generator.com/api/json/get/ceQMMKpidK')]).then(result=>console.log(result));
let newArr=[];
let addArr=(url)=> {
return new Promise((resolve, reject) => {
let xhr = new XMLHttpRequest()
xhr.open('GET', url, true);
xhr.onload = function () {
let json = JSON.parse(this.responseText);
newArr.push(json);
resolve(newArr);
}
xhr.send();
});
}

addReq('http://www.json-generator.com/api/json/get/cfQCylRjuG')
.then(()=>{return addReq('http://www.json-generator.com/api/json/get/cfVGucaXPC')})
.then(item => console.log(item));
(addArr('http://www.json-generator.com/api/json/get/cevhxOsZnS'))
.then(addArr('http://www.json-generator.com/api/json/get/cguaPsRxAi'))
.then(addArr('http://www.json-generator.com/api/json/get/cfDZdmxnDm'))
.then(addArr('http://www.json-generator.com/api/json/get/cfkrfOjrfS'))
.then(addArr('http://www.json-generator.com/api/json/get/ceQMMKpidK'))
.then(result=>console.log(result));