custom-scripts/mccs-it/thermal/public/index.html

52 lines
1.7 KiB
HTML
Raw Normal View History

2024-09-06 23:26:30 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
2024-09-09 20:27:51 +00:00
<title>Thermal Printer Test</title>
2024-09-06 23:26:30 +00:00
</head>
<body>
<h1>Thermal Printer Test</h1>
2024-09-09 20:27:51 +00:00
<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>
2024-09-06 23:26:30 +00:00
<script>
2024-09-09 20:27:51 +00:00
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));
2024-09-06 23:26:30 +00:00
});
</script>
</body>
2024-09-09 20:27:51 +00:00
</html>