Files
quectel-rgmii-toolkit/www/js/handle-at-input.js
Russel Yasol b70ada6b9c ready for PR
2024-10-02 19:22:00 +08:00

36 lines
1.1 KiB
JavaScript

// Handle form submission via JavaScript
document
.getElementById("commandForm")
.addEventListener("submit", function (e) {
e.preventDefault(); // Prevent default form submission
const commandInput = document.getElementById("command").value;
const outputTextarea = document.getElementById("output");
// Make sure input is not empty
if (commandInput.trim() === "") {
outputTextarea.value = "Please enter a valid AT command.";
return;
}
// Send the AT command to the CGI script via fetch
fetch("/cgi-bin/atinout_handler.sh", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: `command=${encodeURIComponent(commandInput)}`,
})
.then((response) => response.json())
.then((data) => {
// Display the response in the textarea
if (data.output) {
outputTextarea.value = data.output;
} else {
outputTextarea.value = "Error: No output received.";
}
})
.catch((error) => {
outputTextarea.value = `Error fetching data: ${error.message}`;
});
});