A
A
Alexander Konovalov2015-11-17 15:58:32
PHP
Alexander Konovalov, 2015-11-17 15:58:32

How to download a certain number of messages?

Hello! I have a chat, messages are added to a text file and displayed on the site, how can I set a message output limit so that only 20 are displayed, for example?

<script>
load_messes();
setInterval(load_messes,2000);
function sendGo(e) {
if (e.keyCode == 13) {
$("#send_massage").click();
}
}
function toggleSmiles() {
  $(".smiles-box").fadeToggle('fast');
}
function smile(a) {
  $("#text-massage").val($("#text-massage").val() + " :" + a + ": ").focus();
  toggleSmiles();
}
</script>

<script>
    var scrolled;
    
    function load_messes()
    {
      $.ajax({
        type: "POST",
        url:  "chatread.php",
        data: "req=ok",
        success: function(test)
        {
        var $mcaht = $("#mcaht"),
          scroll = $mcaht.scrollTop(),
          messageCount = $mcaht.children().length;
    
        $mcaht.empty().append(test);
    
        scroll && $mcaht.scrollTop(scroll);
    
        if(!scrolled || messageCount < $mcaht.children().length) {
          $mcaht.scrollTop(9000000);
          !scrolled && (scrolled = true);
        }
    
        }
      });
    }
  </script>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
X
xmoonlight, 2015-11-17
@xmoonlight

this should be done in PHP

D
Dmitry Kovalsky, 2015-11-17
@dmitryKovalskiy

If you want to take EVERYTHING, and then decide on the client which of them to show, this is a gross mistake and an extra load on resources (the chat will start to slow down sooner or later).
The server logic must decide which list of messages to return for display.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question