-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path141.js
More file actions
34 lines (31 loc) · 731 Bytes
/
Copy path141.js
File metadata and controls
34 lines (31 loc) · 731 Bytes
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
const URL = "https://jsonplaceholder.typicode.com/posts";
const xhr = new XMLHttpRequest();
xhr.open("GET", URL);
xhr.onload = () =>
{
if (xhr.status >= 200 && xhr.status < 300)
{
const data = JSON.parse(xhr.response);
console.log(data);
const id = data[3].id;
const xhr2 = new XMLHttpRequest();
const URL2 = `${URL}/${id}`
console.log(URL2);
xhr2.open("GET", URL2);
xhr2.onload = () =>
{
const data2 = JSON.parse(xhr2.response);
console.log(data2);
}
xhr2.send();
}
else
{
console.log("something went wrong");
}
}
xhr.onerror = () =>
{
console.log("network error");
}
xhr.send();