|
|
|
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); |
|
}) |
|
.catch(error => console.error("Error:", error)); |
|
} |
|
|
|
|
|
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); |
|
window.location.href = "/cart"; |
|
}) |
|
.catch(error => console.error("Error:", error)); |
|
} |
|
|