Jump to content

chat help


Worqy

Recommended Posts

Hello.

 

I'm making a chat for my website.

Now I would need some javascript or Ajax to update my chat.

For now, I'm using this code:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script type="text/javascript">
function updateTable() {
	$("#chatlog").load('getmessage.php');
	}
	setInterval("updateTable()",1000);
</script>	

But it has a problem:

Everytime it updates, the textarea "blinks".

(If you wan't to see what I mean, look at the end of this topic...)

So I would need another code.

Someone that knows any good system for this?

 

// Kevin

 

1) Go to: http://kevingranlund.comli.com/

2) Username: test Password: test

3) Click on the link "Chat"

4) ....

Link to comment
https://forums.phpfreaks.com/topic/201111-chat-help/
Share on other sites

you need to append to the div rather than replace all the html.

 

This means you will need to use .ajax() rather than .load() and your php script will need to only pass back new messages.

 

Something like this might work

 

<script type="text/javascript">
function updateTable() {

    $.ajax({
    
        url: 'getmessage.php',
        type: 'POST',
        datatype: 'html',
        success: function(data) {
        
            $('#chatlog').append(data);
        
        }
    
    });
    
}
setInterval("updateTable()",1000);
</script>   

Link to comment
https://forums.phpfreaks.com/topic/201111-chat-help/#findComment-1055102
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.