Strange javascript (jQuery) behaviour

414
January 18, 2017, at 4:55 PM

I have simple chat that uses ajax to get messages, heres the code:

function get_message_chat() {
  $.ajaxSetup({
    url: "chat.php",
    global: true,
    type: "GET",
    data: "event=get&id=" + mid + "&t=" + (new Date).getTime()
  });
  $.ajax({
    success: function(msg_j) {
      if (msg_j.length > 2) {
        var obj = JSON.parse(msg_j);
        for (var i = 0; i < obj.length; i++) {
          console.log(msg_j.length);
          if (mid >= obj[i].id) {
            continue;
          }
          mid = obj[i].id;
          name = obj[i].name;
          msg = obj[i].msg
          $("#msg-box ul").append("<li><b><span class=\"username\" >" + name + "</span></b>:<span id=\"msgid_" + mid + "\" class=\"messsage\" style=\"color:black;\" > " + msg + "</span></li>");
          if (msg.indexOf('@' + username) != -1) {
            $("#msgid_" + mid).css('font-weight', 'bold');
          }
        }
        $("#msg-box").scrollTop(2000);
      }
    }
  });
  setTimeout(get_message_chat, 2000);
}
mid = 0;

It grabs messages from php script "starts from mid ID". Then it shows messages to chat(appends to ul) and sets mid to new message id and then loop repeats. The problem is that it stucks fter mid = 9 for some reason. I still have more messages coming:

[{"id":"10","name":"user1","msg":"messages1234"},
{"id":"11","name":"user2","msg":"messages5678"}]

But they wont display. Everyting looks fine, but I can't understand why is that happening. Thank you for all comments.

Rent Charter Buses Company
READ ALSO
Show the responce of ajax is not working

Show the responce of ajax is not working

Hi I am trying to replace the table->tr->td with new td I have tried like this but it is not working

321
adding events to wordpress full calendar via backoffice

adding events to wordpress full calendar via backoffice

I have successfully managed to integrate JQuery Full Calendar to my Wordpress site, but i want to be able to add events to the calendar via the backoffice rather than using a JSON fileAny idea on how to do it ?

432
How to animate each div individually

How to animate each div individually

I am trying to show products and when I apply the animation it applies to the whole div

384
Arrow Right Type Sidebar

Arrow Right Type Sidebar

I've been banging this problem for hours and still can't figure out how to achieve this arrow right type sidebarI want the look of my sidebar like this

408