Updating the callbacks function.
This commit is contained in:
@@ -27,33 +27,30 @@ export function raceCondition() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function callbacks() {
|
export function callbacks() {
|
||||||
var xhr = new XMLHttpRequest();
|
let xhr = new XMLHttpRequest();
|
||||||
xhr.open("GET", "http://localhost:3000/orders");
|
let statuses = [];
|
||||||
|
xhr.open("GET", "http://localhost:3000/orderStatuses");
|
||||||
|
|
||||||
xhr.onload = () => {
|
xhr.onload = () => {
|
||||||
const data = JSON.parse(xhr.responseText);
|
statuses = JSON.parse(xhr.responseText);
|
||||||
const itemId = data[0].itemIds[0];
|
|
||||||
|
let xhr2 = new XMLHttpRequest();
|
||||||
|
xhr2.open("GET", "http://localhost:3000/orders/1");
|
||||||
|
|
||||||
const xhr2 = new XMLHttpRequest();
|
|
||||||
xhr2.open("GET", `http://localhost:3000/items/${itemId}`);
|
|
||||||
xhr2.onload = () => {
|
xhr2.onload = () => {
|
||||||
const data = JSON.parse(xhr2.responseText);
|
const order = JSON.parse(xhr2.responseText);
|
||||||
const categoryId = data.itemCategoryId;
|
|
||||||
|
|
||||||
const xhr3 = new XMLHttpRequest();
|
const description = statuses.map(t => {
|
||||||
xhr3.open("GET", `http://localhost:3000/itemCategories/${categoryId}`);
|
if (t.id === order.orderStatusId) {
|
||||||
|
return t.description;
|
||||||
|
}
|
||||||
|
})[0];
|
||||||
|
|
||||||
xhr3.onload = () => {
|
setText(`Order Status: ${description}`);
|
||||||
const {description} = JSON.parse(xhr3.responseText);
|
|
||||||
|
|
||||||
setText(`Order Item Category: ${description}`);
|
|
||||||
}
|
|
||||||
xhr3.onerror = () => setText(xhr3.statusText);
|
|
||||||
xhr3.send();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
xhr2.onerror = () => setText(xhr2.statusText);
|
|
||||||
xhr2.send();
|
xhr2.send();
|
||||||
};
|
};
|
||||||
xhr.onerror = () => setText(xhr.statusText);
|
|
||||||
xhr.send();
|
xhr.send();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user