Note that there are some explanatory texts on larger screens.

plurals
  1. PORefresh the content without page refresh
    text
    copied!<p>hello i have developed the chat application using socket.io, expressjs and mongoose it works fine. it refreshes after some seconds and fetches new clients from db if exist. problem is that user can feel that div is refreshsing.and also some time take soem time in response. how to avoid this case. here is my code <strong>This is my server side code</strong></p> <pre><code> setInterval(function () { var allOnLine; allOnLine = io.sockets.clients(); for (var client in allOnLine) { if (allOnLine[client].username == "undefined") { continue; } else { notifyAll(allOnLine[client].username); } } }, 50000); </code></pre> <p>and here is notify all method</p> <pre><code>function notifyAll(userName) { contactModel.find({'userId':userName}, (function (err, contactModel) { usernames = []; var contacts = contactModel; for (var a = 0; a &lt; contacts.length; a++) { usernames[a] = contacts[a].contactId; } var allOnLine; allOnLine = io.sockets.clients(); for (var client in allOnLine) { if (allOnLine[client].username == "undefined") { continue; } else { for (var i = 0; i &lt; usernames.length; i++) { if (allOnLine[client].username == usernames[i]) { usernames[i] = usernames[i] + " -On"; } allOnLine[client].username); } } } io.sockets.to(userName).emit('updateusers', usernames); })); } </code></pre> <p><strong>This is my client code</strong></p> <pre><code>socket.on('updateusers', function(usernames) { jQuery('#usernames').html(''); jQuery.each(usernames, function(key, value) { jQuery('#usernames').append('&lt;div class="chatContact" id="chatLink" onclick="privateChat(\''+value+'\')"&gt;' ); }} </code></pre> <p>any help i had also posted this question but no answer</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload