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
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
Share on other sites

and now it shows the messages again and again.

 

If you had actually read my post you would have realised that I said you would have to alter your php script to only pass back new messages.

 

 

oo.. Sorry. I was just on my phone so I didn't see it. Sorry once again.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.