custom-scripts/mccs-it/thermal/public/index.html
2024-09-09 16:27:51 -04:00

52 lines
1.7 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Thermal Printer Test</title>
</head>
<body>
<h1>Thermal Printer Test</h1>
<form id="printForm">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required><br><br>
<label for="studentId">Student ID:</label>
<input type="text" id="studentId" name="studentId" required><br><br>
<button type="submit">Test Print</button>
</form>
<script>
document.getElementById('printForm').addEventListener('submit', (event) => {
event.preventDefault(); // Prevent the form from submitting normally
// Get the form data
const formData = new FormData(event.target);
const username = formData.get('username');
const studentId = formData.get('studentId');
// Send a POST request with the form data to the server
fetch('/test-print', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
username: username,
studentId: studentId,
}),
})
.then(response => {
if (response.ok) {
return response.text(); // or .json() if your server returns JSON
} else {
throw new Error('Failed to send print request');
}
})
.then(message => alert(message))
.catch(error => alert('Error: ' + error));
});
</script>
</body>
</html>