Skip to content
Snippets Groups Projects
Commit b379f594 authored by Christophorus Dharma Winata's avatar Christophorus Dharma Winata
Browse files

feat: checkout frontend script

parent 6ce2f40c
Branches
Tags
No related merge requests found
var cartDataArray;
cartList = () => {
var cartListItems = document.getElementById("cart-list");
const xhr = new XMLHttpRequest();
......@@ -37,4 +38,32 @@ cartList = () => {
console.log(responseData.message);
}
};
}
submitCheckout = () => {
// send cartDataArray back as post method
const cartData = new FormData();
cartData.append("data", cartDataArray);
const xhr = new XMLHttpRequest();
xhr.open('POST', '../../server/controllers/transaction.php', true);
xhr.send(cartData);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
try {
// Process the response data here
var responseData = JSON.parse(xhr.responseText);
if (responseData.success) {
alert("Check out success")
location.reload();
} else {
alert("error: " + responseData.message)
}
} catch (error) {
alert(error)
}
} else if (xhr.status === 404) {
var responseData = JSON.parse(xhr.responseText);
console.log(responseData.message);
}
};
}
\ No newline at end of file
<?php
?>
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment