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