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) .... Quote Link to comment 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> Quote Link to comment 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" .... Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.