-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path142.js
More file actions
55 lines (51 loc) · 1.14 KB
/
Copy path142.js
File metadata and controls
55 lines (51 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const URL = "https://jsonplaceholder.typicode.com/posts";
function sendRequest(method, url)
{
return new Promise(function (resolve, reject)
{
const xhr = new XMLHttpRequest();
xhr.open(method, url);
xhr.onload = function ()
{
if (xhr.status >= 200 && xhr.status < 300)
{
resolve(xhr.response);
}
else
{
reject(new Error("Something Went wrong"));
}
}
xhr.onerror = function ()
{
reject(new Error("Something went wrong"));
}
xhr.send();
})
}
sendRequest("GET", URL)
.then(response =>
{
const data = JSON.parse(response);
// console.log(data)
return data;
})
.then(data =>
{
const id = data[3].id;
return id;
})
.then(id =>
{
const url = `${URL}/${id}ssss`;
return sendRequest("GET", url);
})
.then(newResponse =>
{
const newData = JSON.parse(newResponse);
console.log(newData);
})
.catch(error =>
{
console.log(error);
})