Spaces:
Runtime error
Runtime error
Update templates/menu.html
Browse files- templates/menu.html +16 -13
templates/menu.html
CHANGED
@@ -553,19 +553,22 @@ function addToCartFromModal() {
|
|
553 |
body: JSON.stringify(cartPayload)
|
554 |
})
|
555 |
.then(response => response.json())
|
556 |
-
.then(data => {
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
}
|
564 |
-
.
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
|
|
|
|
|
|
569 |
function updateCartUI(cart) {
|
570 |
if (!Array.isArray(cart)) {
|
571 |
console.error('Invalid cart data:', cart);
|
|
|
553 |
body: JSON.stringify(cartPayload)
|
554 |
})
|
555 |
.then(response => response.json())
|
556 |
+
.then(data => {
|
557 |
+
if (data.success) {
|
558 |
+
alert('Item added to cart successfully!');
|
559 |
+
updateCartUI(data.cart); // Update cart UI after adding an item
|
560 |
+
const modal = document.getElementById('itemModal');
|
561 |
+
const modalInstance = bootstrap.Modal.getInstance(modal);
|
562 |
+
modalInstance.hide();
|
563 |
+
} else {
|
564 |
+
alert(data.error || 'Failed to add item to cart.');
|
565 |
+
}
|
566 |
+
})
|
567 |
+
.catch(err => {
|
568 |
+
console.error('Error adding item to cart:', err);
|
569 |
+
alert('An error occurred while adding the item to the cart.');
|
570 |
+
});
|
571 |
+
}
|
572 |
function updateCartUI(cart) {
|
573 |
if (!Array.isArray(cart)) {
|
574 |
console.error('Invalid cart data:', cart);
|