I’ve been facing an issue for several days now and can’t seem to pinpoint the cause. My webpage consists of just two chat displays. It originally had only one, but I’ve had to add a second one recently. This page is used as a browser source in OBS, in case that’s relevant. There’s a chat for regular users and another one for premium users.
First, take a look at the code:
const fetchMessages = function(){
$.post('/get', function(data){
let newMessages = $();
data.data1.forEach(function(msg){
newMessages = newMessages.add(`
<div class="message-container" id="${msg.element}">
<img src="${msg.avatarUrl}" alt="Avatar" class="avatar">
<p><span class="name">${msg.name}:</span><img src="${msg.logo}" alt="Logo" class="logo"/><span class="content">${msg.message}</span></p>
</div>
`);
});
$('#messages').empty().append(newMessages);
let newMessages2 = $();
data.data2.forEach(function(msg){
newMessages2 = newMessages2.add(`
<div class="message-container" id="${msg.element}">
<img src="${msg.avatarUrl}" alt="Avatar" class="avatar">
<p><span class="name">${msg.name}:</span><span class="content">${msg.message}</span></p>
</div>
`);
});
$('#messages2').empty().append(newMessages2);
});
};
fetchMessages();
setInterval(fetchMessages, <%= refreshRate %>);
I’m not sure why I named the function fetchMessages when I’m making POST requests. It’s something I did a while back.
My issue is that only the second chat (messages2) is being displayed; the other div (messages) remains empty. If I use data1 in the second chat, both display messages, but they show the same messages.
It must be a silly mistake somewhere, but I can’t figure it out. Can anyone help?