I have a chat function on the page. When two users are chatting with each other, I could not find a way to automatically load new messages user B on chat window of user A. That's why I used
<script type="text/javascript">
$(document).ready(function(){
$("#getBuddieContacts").load("ajax_getContactsList.php");
$("#getFriendsRequestList").load("ajax_getMessages.php");
});
setInterval(function() {$("#getBuddieContacts").load("ajax_getContactsList.php");}, 5000);
setInterval(function() {$("#getFriendsRequestList").load("ajax_getMessages.php");}, 5000);
</script>
PHP scripts returns the full chat (from 0 to latest) each time when script is loaded. (I don't know the technique of showing user B's sent message immediately on user A's chat screen). :(
The code works okay but whenever we try to copy / paste or select any text coming from ajax loaded files, the content reloads and seems like jumping on the screen (not jumping display wise, but behavior wise).
So, my question is, how can I make the changes so that the new message from user B can be displayed on user A screen or what technique should I use instead ?