Send cars
This commit is contained in:
45
index.html
45
index.html
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
<h2>Choose cars</h2>
|
<h2>Choose cars</h2>
|
||||||
<button id="addCarBtn">Add Car</button>
|
<button id="addCarBtn">Add Car</button>
|
||||||
|
<button id="applyCarsBtn">Apply Cars</button>
|
||||||
|
|
||||||
<div id="carList"></div>
|
<div id="carList"></div>
|
||||||
|
|
||||||
@@ -83,6 +84,48 @@
|
|||||||
<script>
|
<script>
|
||||||
const addCarBtn = document.getElementById("addCarBtn");
|
const addCarBtn = document.getElementById("addCarBtn");
|
||||||
const carList = document.getElementById("carList");
|
const carList = document.getElementById("carList");
|
||||||
|
const applyCarsBtn = document.getElementById("applyCarsBtn");
|
||||||
|
|
||||||
|
applyCarsBtn.addEventListener("click", applyCars);
|
||||||
|
|
||||||
|
function applyCars() {
|
||||||
|
// Zoek alle car blocks
|
||||||
|
const blocks = document.querySelectorAll(".car-block");
|
||||||
|
|
||||||
|
let cars = [];
|
||||||
|
|
||||||
|
blocks.forEach(block => {
|
||||||
|
const carSelect = block.querySelector(".car-select");
|
||||||
|
const skinSelect = block.querySelector(".skin-select");
|
||||||
|
|
||||||
|
const carName = carSelect?.value || null;
|
||||||
|
const skinName = skinSelect?.value || null;
|
||||||
|
|
||||||
|
if (carName) {
|
||||||
|
cars.push({
|
||||||
|
car: carName,
|
||||||
|
skin: skinName
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Payload klaar
|
||||||
|
const payload = { cars };
|
||||||
|
|
||||||
|
console.log("Sending cars:", payload);
|
||||||
|
|
||||||
|
fetch("/changecars", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
|
body: JSON.stringify(payload)
|
||||||
|
})
|
||||||
|
.then(res => res.json())
|
||||||
|
.then(data => {
|
||||||
|
console.log("Server response:", data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async function addCar() {
|
async function addCar() {
|
||||||
const wrapper = document.createElement("div");
|
const wrapper = document.createElement("div");
|
||||||
@@ -157,7 +200,7 @@
|
|||||||
const car = cars.find(c => c.name === selectedCar);
|
const car = cars.find(c => c.name === selectedCar);
|
||||||
const cfg = car.skins.find(x => x.name === selectedSkin);
|
const cfg = car.skins.find(x => x.name === selectedSkin);
|
||||||
|
|
||||||
try{
|
try {
|
||||||
updateImage(cfg.image);
|
updateImage(cfg.image);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
updateImage("");
|
updateImage("");
|
||||||
|
|||||||
Reference in New Issue
Block a user