Spaces:
Sleeping
Sleeping
File size: 1,088 Bytes
54229f6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
<!DOCTYPE html>
<html>
<head>
<title>Rust Hello App</title>
</head>
<body>
<h2>Rust + Flask + JS Fetch (Local HTML + HF Backend)</h2>
<label for="name">Enter your name:</label>
<input type="text" id="name" name="name">
<button onclick="sendData()">Say Hello</button>
<p id="result" style="font-weight:bold;"></p>
<script>
function sendData() {
const name = document.getElementById('name').value;
fetch("https://<your-hf-space>.hf.space/process", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: name=${encodeURIComponent(name)}
})
.then(response => response.text())
.then(data => {
document.getElementById("result").innerText = data;
})
.catch(error => {
document.getElementById("result").innerText = "Error: " + error;
});
}
</script>
</body>
</html> |