Spaces:
Sleeping
Sleeping
Update static/script.js
Browse files- static/script.js +21 -0
static/script.js
CHANGED
|
@@ -40,3 +40,24 @@ function addToCart(foodItem, suggestions) {
|
|
| 40 |
alert(`Added to cart: ${foodItem} (x${quantity})`);
|
| 41 |
console.log('Cart:', cart);
|
| 42 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
alert(`Added to cart: ${foodItem} (x${quantity})`);
|
| 41 |
console.log('Cart:', cart);
|
| 42 |
}
|
| 43 |
+
|
| 44 |
+
function addToCart(itemName) {
|
| 45 |
+
const quantity = document.getElementById(`quantity-${itemName}`).value;
|
| 46 |
+
|
| 47 |
+
fetch("/add_to_cart", {
|
| 48 |
+
method: "POST",
|
| 49 |
+
headers: {
|
| 50 |
+
"Content-Type": "application/json",
|
| 51 |
+
},
|
| 52 |
+
body: JSON.stringify({ name: itemName, quantity: quantity }),
|
| 53 |
+
})
|
| 54 |
+
.then((response) => response.json())
|
| 55 |
+
.then((data) => {
|
| 56 |
+
alert(data.message);
|
| 57 |
+
// Optionally update cart count in the UI
|
| 58 |
+
})
|
| 59 |
+
.catch((error) => {
|
| 60 |
+
console.error("Error:", error);
|
| 61 |
+
});
|
| 62 |
+
}
|
| 63 |
+
|