Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	| // Add item to cart | |
| function addToCart(name, price) { | |
| fetch("/add_to_cart", { | |
| method: "POST", | |
| headers: { "Content-Type": "application/json" }, | |
| body: JSON.stringify({ name: name, price: price }) | |
| }) | |
| .then(response => response.json()) | |
| .then(data => { | |
| alert(data.message); // Display message that item was added | |
| }) | |
| .catch(error => console.error("Error:", error)); | |
| } | |
| // Place order (if additional client-side logic is required) | |
| function placeOrder() { | |
| const email = document.getElementById("email").value; | |
| if (!email) { | |
| alert("Please enter your email to place the order."); | |
| return; | |
| } | |
| fetch("/place_order", { | |
| method: "POST", | |
| headers: { "Content-Type": "application/json" }, | |
| body: JSON.stringify({ email: email }) | |
| }) | |
| .then(response => response.json()) | |
| .then(data => { | |
| alert(data.message); // Display success message | |
| window.location.href = "/cart"; // Redirect to the cart page | |
| }) | |
| .catch(error => console.error("Error:", error)); | |
| } | |
