-2
Good community. I am working on this chat system, very simple.
I don’t understand why I don’t get messages in real time. I can only receive messages from another user if you close and open the div again, then the message appears.
How can I fix it? As I am not very comfortable with ajax I ask for your help.
I think the problem will be in the last function, message cycle:
function message_cycle()
{   
    $.ajax({
        url:'chat.class.php',
        type:'POST',
        data:'unread=true',
        dataType:'JSON',
        success:function(data){             
            $.each(data , function( index, obj ) {
                var user = index;                   
                var box  = $("#jd-chat").find("div#2").parents(".jd-user");
                $(".jd-online").find(".light").hide();
                $.each(obj, function( key, value ) {
                    if($.inArray(user,open) !== -1 )                                            
                        $(box).find(".jd-body").append("<span style='display:block'  class='other'> " + value + "</span>");                     
                    else            
                        snd.play();
                        $(".jd-online").find("span#" + user + " .light").show();        
                });
            });             
        }
    });
}
setInterval(message_cycle,1000);
});  
Any idea?
I found out where the problem was instead of div id = 2
var box  = $("#jd-chat").find("div#2").parents(".jd-user");
called for by span that receives text from user Sender and user receiver
var box  = $("#jd-chat").find(".me").parents(".jd-user");
she now receives the messages and soon shows the messages q exist without closing and open the div
Hello I’ll give a suggestion a few months ago I was using Mibew he is very good, give a look at this link https://www.youtube.com/watch?v=nWa8svuraC0
– Rodrigo Araujo
https://www.youtube.com/watch?v=iyg_fk36p0Y&list=PLBOh8f9FoHHjz91tWQ5AtBoVwOVhP1Di7 has everything you need here and a source code https://github.com/howCodeORG/Messenger
– Gabriel Brandao