Worqy Posted May 8, 2010 Share Posted May 8, 2010 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 More sharing options...
isedeasy Posted May 8, 2010 Share Posted May 8, 2010 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 More sharing options...
Worqy Posted May 8, 2010 Author Share Posted May 8, 2010 Still "blinking" and now it shows the messages again and again. Ex: If I write "Hello" after some time I get: "Hello" "Hello" "Hello" "Hello" .... Link to comment https://forums.phpfreaks.com/topic/201111-chat-help/#findComment-1055113 Share on other sites More sharing options...
Worqy Posted May 8, 2010 Author Share Posted May 8, 2010 Does anybody have some tips or anything that could help me making my chat program? Link to comment https://forums.phpfreaks.com/topic/201111-chat-help/#findComment-1055148 Share on other sites More sharing options...
isedeasy Posted May 8, 2010 Share Posted May 8, 2010 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. Link to comment https://forums.phpfreaks.com/topic/201111-chat-help/#findComment-1055163 Share on other sites More sharing options...
Worqy Posted May 9, 2010 Author Share Posted May 9, 2010 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 https://forums.phpfreaks.com/topic/201111-chat-help/#findComment-1055280 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.