File size: 1,021 Bytes
fbe9c7c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1b10c0c
fbe9c7c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>FastAPI Example</title>
</head>
<body>
    <h1>FastAPI Input Example</h1>
    <input type="text" id="user_input" placeholder="Enter something...">
    <button onclick="submitInput()">Submit</button>
    <p id="response"></p>

    <script>
        function submitInput() {
            const input = document.getElementById("user_input").value;
            fetch("/submit", {
                method: "POST",
                headers: {
                    "Content-Type": "application/json"
                },
                body: JSON.stringify({ user_input: input })
            })
            .then(response => response.json())
            .then(data => {
                document.getElementById("response").textContent = "Response: " + data.message;
            })
            .catch(error => console.error("Error:", error));
        }
    </script>
</body>
</html>