added event listener
Browse files- index.html +13 -12
index.html
CHANGED
@@ -10,7 +10,7 @@
|
|
10 |
<div class="card">
|
11 |
<h1>Welcome to my GPT test environment!</h1>
|
12 |
<p>Enter a prompt in the textbox to get started</p>
|
13 |
-
<textarea name="prompt" id="prompt" cols="30" rows="10"></textarea>
|
14 |
<button id="submit">Submit</button>
|
15 |
<p id="response"></p>
|
16 |
</div>
|
@@ -20,16 +20,17 @@
|
|
20 |
const textbox = document.querySelector("#prompt")
|
21 |
const res = document.querySelector("#response")
|
22 |
const prompt = textbox.value
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
34 |
</script>
|
35 |
</html>
|
|
|
10 |
<div class="card">
|
11 |
<h1>Welcome to my GPT test environment!</h1>
|
12 |
<p>Enter a prompt in the textbox to get started</p>
|
13 |
+
<textarea name="prompt" id="prompt" cols="30" rows="10"></textarea><br>
|
14 |
<button id="submit">Submit</button>
|
15 |
<p id="response"></p>
|
16 |
</div>
|
|
|
20 |
const textbox = document.querySelector("#prompt")
|
21 |
const res = document.querySelector("#response")
|
22 |
const prompt = textbox.value
|
23 |
+
btn.on("click", event => {
|
24 |
+
fetch(`/gpt?prompt=${prompt}`)
|
25 |
+
.then(res => res.json())
|
26 |
+
.then(res => {
|
27 |
+
console.log(res)
|
28 |
+
res.textContent = res
|
29 |
+
})
|
30 |
+
.catch(err => {
|
31 |
+
console.log(err)
|
32 |
+
res.textContent = err
|
33 |
+
})
|
34 |
+
})
|
35 |
</script>
|
36 |
</html>
|