-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-chatrooms.js
29 lines (26 loc) · 1.13 KB
/
get-chatrooms.js
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
function displayChatrooms() {
fetch('http://192.168.1.243:3000/chatrooms')
.then(response => response.json())
.then(data => {
const chatroomContainer = document.getElementById('chatroomContainer');
chatroomContainer.innerHTML = ''; // Clear previous content
if (data.chatrooms && Array.isArray(data.chatrooms)) {
data.chatrooms.forEach(chatroom => {
const pElement = document.createElement('p');
pElement.className = "chatroomBox"
pElement.textContent = `Name: ${chatroom.name} Creator ${chatroom.username}`;
chatroomContainer.appendChild(pElement);
});
} else {
const pElement = document.createElement('p');
pElement.textContent = 'No chatrooms found.';
chatroomContainer.appendChild(pElement);
}
})
.catch(error => {
console.error('Error fetching chatrooms:', error);
const chatroomContainer = document.getElementById('chatroomContainer');
chatroomContainer.innerHTML = '<p>Error fetching chatrooms.</p>';
});
}
setInterval(displayChatrooms, 5);