Load products on page load
This commit is contained in:
parent
a50ba6f68a
commit
26fb8073ed
2 changed files with 18 additions and 7 deletions
19
index.html
19
index.html
|
|
@ -1,5 +1,14 @@
|
|||
<script src="/scripts/main.js"></script>
|
||||
|
||||
<button type="button" onclick="loadProducts()">Load Products</button>
|
||||
|
||||
<p id="demo"></p>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>
|
||||
Toddler Shop
|
||||
</title>
|
||||
<script src="/scripts/main.js"></script>
|
||||
</head>
|
||||
|
||||
<body onload="loadProducts()">
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
var all_products
|
||||
|
||||
async function makeAPIRequest(request) {
|
||||
try {
|
||||
const response = await fetch(request);
|
||||
|
|
@ -10,7 +12,7 @@ async function makeAPIRequest(request) {
|
|||
|
||||
async function loadProducts() {
|
||||
const loadProductRequest = new Request("http://127.0.0.1:8000/products")
|
||||
const result = await makeAPIRequest(loadProductRequest)
|
||||
console.log(result)
|
||||
all_products = await makeAPIRequest(loadProductRequest)
|
||||
console.log("Loaded products:", all_products)
|
||||
}
|
||||
|
||||
Loading…
Reference in a new issue