-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.html
48 lines (41 loc) · 1.33 KB
/
test.html
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Test Page</title>
</head>
<body>
<h1>Search for Files</h1>
<form>
<label for="searchTerm">Enter a search term:</label>
<input type="text" id="searchTerm" name="searchTerm">
<input type="button" value="Search" onclick="searchFiles()">
</form>
<div id="searchResults"></div>
<script>
const socket = new WebSocket("ws://localhost:3000");
socket.addEventListener("open", function(event) {
console.log("Connected to server");
});
socket.addEventListener("message", function(event) {
const results = JSON.parse(event.data);
let output = "<ul>";
for (const filename of results) {
output += "<li>" + filename + "</li>";
}
output += "</ul>";
document.getElementById("searchResults").innerHTML = output;
console.log(output);
});
socket.addEventListener("error", function(event) {
console.error("WebSocket error:", event);
alert("An error occurred while trying to search for files. Please try again later.");
});
function searchFiles() {
const searchTerm = document.getElementById("searchTerm").value;
console.log("search term: " + searchTerm);
socket.send(searchTerm); // Send only the search term to the server
}
</script>
</body>
</html>