express: thanks ChatGPT!
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
3eb17c1935
commit
5c1b0ce6ff
4 changed files with 757 additions and 0 deletions
55
express/index.html
Normal file
55
express/index.html
Normal file
|
@ -0,0 +1,55 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Random Animal Generator</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Random Animal Generator</h1>
|
||||
<p id="animal-name">Click a button to get a random animal:</p>
|
||||
<button id="button1">Button 1</button>
|
||||
<button id="button2">Button 2</button>
|
||||
|
||||
<script>
|
||||
// Function to fetch a random animal name from the server
|
||||
async function getRandomAnimal() {
|
||||
try {
|
||||
const response = await fetch('/getRandomAnimal');
|
||||
const data = await response.json();
|
||||
document.getElementById('animal-name').textContent = data.animalName;
|
||||
} catch (error) {
|
||||
console.error('Error fetching data:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Add click event listeners to the buttons
|
||||
document.getElementById('button1').addEventListener('click', () => {
|
||||
recordButtonClick('Button 1');
|
||||
});
|
||||
|
||||
document.getElementById('button2').addEventListener('click', () => {
|
||||
recordButtonClick('Button 2');
|
||||
});
|
||||
|
||||
// Function to record button clicks on the server
|
||||
async function recordButtonClick(buttonName) {
|
||||
try {
|
||||
await fetch('/recordButtonClick', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ buttonName }),
|
||||
});
|
||||
getRandomAnimal(); // Load another random animal
|
||||
} catch (error) {
|
||||
console.error('Error recording button click:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Initial random animal load
|
||||
getRandomAnimal();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue