Hey guys.
Today I want to start a discussion about real-time chat for Instant Messenger, this is one incredible and essential plugins that we really need to have.
I don't know if is in progress the option to made the chat real time, but I want to share some of my experiments, I don't have experience in PHP socket but I have an easy idea that may work.
I have 2 ideas to make the chat real-time without a lot of code,
1 - Reload the chat div showing new messages (without reloading the entire page), using javascript using setInterval(function()
2 - Using Jquery to submit and clear the form after clicking on "Send message"
I already try the reload chat process, but no luck.
<script type="text/javascript">
function loadlink(){
$('#links').load('',function () {
$(this).unwrap();
});
}
loadlink(); // This will run on page load
setInterval(function(){
loadlink() // this will run after every 5 seconds
}, 5000);
</script>
I put the #links with one of the divs for example <div class="im-table im-messages im-body"> line 108 in messages.php and the final code is <div class="im-table im-messages im-body" id="links">
Is reloading, but is not in a good way.
Any of you guys have an advice or can we work together on this, maybe you guys have a better idea to do this in an easy way, or if you know which DIV is a better option to reload, or maybe message.php is not the correct file.
I install the example in this tutorial
https://css-tricks.com/jquery-php-chat/ and is working great.
In order to periodically Checking for New Messages, they are using
<body onload="setInterval('chat.update()', 1000)">
, but in this case I dont know which funtions request to onload.
Thank you any idea will be great